DataSource Controls :: Combining Insert And Select Statements?
Jun 10, 2010
[Code]....
I want to insert a record into a log table ONLY if one exact copy already doesn't exist within ten days, what is a good way to do in one stored procedure what I do above in two?
I'm using the 'Configure Data Source' wizard to connect to my database and show the dataset in Gridview. I want to be able to update, insert and delete entries but am unsure how to build the query. I can write simple update statments to change database entries but how can I do this for entries that have been changed within the gridview?
A bit new to buttonfields in gridviews - Did a bit of research and most of the stuff I came up with had the gridviews with data bound like so :
[Code]....
private void BindGridControl() {//method created so that the binded gridview can allow paging controls DataTable dt = new DataTable(); try { /*Gridview requires another column either a checkbox or a hyperlink column that * can drill down another level and load a page where user can edit the data/cheque * Will place an exception here that will prompt a window to notify users that there were no rows returned */ GridView1.Visible = true; sqlConn.Open(); sqlSearch = "select store_nbr as [Store number],date as Date,data_type as [Data type],acct_1 as [Account 1], "; sqlSearch += "amt_1 as [Amount 1],acct_2 as [Account 2],amt_2 as [Amount 2], "; sqlSearch += "acct_3 as [Account 3], amt_3 as [Amount 3], cheque_nbr as [Cheque Number], "; sqlSearch += "cheque_amt as [Cheque Amount], gst_hst as [GST/HST], qst as [QST],comments as [Comment] "; sqlSearch += "from SimpData where store_nbr = '" + StoreNum + "'"; sqlCmd = new SqlCommand(sqlSearch, sqlConn); SqlDataAdapter adapter = new SqlDataAdapter(sqlCmd); adapter.Fill(dt); if (dt.Rows.Count > 0) { //if there are rows returned bind the datasource to the gridview GridView1.DataSource = dt; GridView1.DataBind(); } else { //label control notifies user that there are no rows found lblResults.Text = "Search returned no rows"; } My ButtonFields<Columns> <asp:ButtonField ButtonType="Button" CommandName="Select" HeaderText="Select item" ShowHeader="True" Text="Select1"> <ControlStyle Width="50px" /> <HeaderStyle Font-Size="XX-Small" /> </asp:ButtonField> <asp:ButtonField ButtonType="Button" CommandName="Select" HeaderText="Select item" ShowHeader="True" Text="Select2"> <ControlStyle Width="50px" /> <HeaderStyle Font-Size="XX-Small" /> </asp:ButtonField> <asp:ButtonField ButtonType="Button" CommandName="Select" HeaderText="Select item " ShowHeader="True" Text="Select3"> <ControlStyle Width="50px" /> <HeaderStyle Font-Size="XX-Small" /> </asp:ButtonField> </Columns>
I tried to find a LINQ section on this forum, but couldn't, so I'll post this here since is deals with LINQ, C#, MVC, SQL Server, and well...just about everything.
Here's the details....My Application is an ASP .Net MVC 1.0 app, using C# 3.5, SQL Server 2005 Std, and LINQ to Entity.
In my View, I have numerous Html.CheckBox controls, they get passed to my Controller as a string collection via a JQuery Ajax call. The values of each checkbox are seperated by a comma(,). I then Split the string, to get the individual values. The overall purpose to to allow users to build a custom report with only the data elements they have checked the boxes for. Here is my controller:
[Code]....
The part that I am having a problem with is that I only want to Insert the data elements into my DB table for the ones that the user has selected the checkbox for. So, for example, I'd like to do something like this:
[Code]....
I don't know if there is a LINQ switch statement in which I can access outside variables and the columns of the table, or any thing like that.
Is it possible to add multiple select statements in a single stored procedure. The select statements are getting data from different tables. If yes, could anybody provide an example in adding multiple select statements, which retrieve data from different tables in a stored procedure.
I am trying to create a multi column listbox by combining fields in Linq select statement, as Let Name = Last + First. The problem is how to pad the Last column with spaces as you would in SQL using REPLICATE so when I bind the listbox to the data, it looks like two columns.
How would you handle an INSERT that gets some values from another table using SELECT, where you wanted some values to come from the source table record and other values to come from a different parameter source like a session value? Is this possible?
I get the following error on the e.Command.Parameters("@latestRowId").Value line. It was working, but now not and I'm not sure why? Conversion from type 'DBNull' to type 'Integer' is not valid.
I have a select statement and want to be able to insert some spaces in the returned data:
[Code]....
For the parts with ' - ', I want to remove the dash and simply put spaces now. But when I remove the dash and put 4 spaces, I only get one space. How do I put in those 4 spaces?
I have three table like above, table C is mapping table which has foreign key of Table A and B.How can i select and insert data in Table C using Entity Frame Work?
Ok I hope I can describe this clearly. This is all demo code nothing in production.Right now I have a stored procedure that is
[Code]....
This will return only one row as ID is uniquethen I have a procedure that gets all the colors that are available for this model number and i use that data in a drop down list, it is like this
[Code]....
this can return multiple rows with different colors.Right now i am opening a connection getting the product data, consuming that to properties of a class, then to get the data from the Colors I open another connection run the procedure with the model parameter being the model returned from the first sproc and bind that to my ddl.I want to do this in one connection and just get two result sets back. So how do I set the parameter of the second procedure to be the model from the first?
I have a page with a SqlDataSource and a GridView which displays products (Title, Description, Price) pulled from a SQL table (let's call it Table1). I have added a TemplateField with a DropDownList so the buyer can choose how many they'd like. I've also added a ButtonField so the user can click to add the items to his/her shopping cart. All this works really well. The inserting is done in the Code Behind into Table2 (the code for this is provided below)
I then have a second page (ViewOrder) with a SqlDataSource and a GridView which simply displays the contents of Table2.
Here's the problem. If I add three Product 1's, ViewOrder displays a row with 3 product 1's. That's fine. But, if I then add a further 2 Product 1's, ViewOrder now displays TWO rows, one with 3 and one with 2 OF THE SAME PRODUCT.
Now, as it's the same product, I'd like ViewOrder to display ONE row with FIVE Product 1's.
Here's the code which does the Inserting into Table2:
[Code]....
myVal is the SelectedValue of the DropDownList and MealValue is a calculated value of the unit cost * myVal.
I know there has to be a way to do this but for some reason I keep getting it wrong. I have one query which pulls all of the cities from a zipcode database like so:
[Code]....
Then I have another which counts the records from a transactions table per city, like so:
[Code]....
Only the zipcode is stored in the transactions table, so the idea here is to get a list off all the distinct cities that reside in the state. Once I have the cities, I want a count for each city as a whole, so I need to go back in and get all of the zipcodes that make up one city, and then count the transactions for those zipcodes. It works using the first query above, looping through them and then executing the second for every pass. But shouldn't there be a way to do it all in one query?
I want to issue an INSERT command for an SQL Server table using DataAdapter without first issuing a SELECT command. Could anybody send me lines of code to handle this? Also how do i manage INSERT into selective table columns (I have 10 columns but i only want to update 2 of them)?
I'm new to Linq. I have searched and searched the web for a soluion, and can't find anything. I have a Linq query and I want to insert a row ("Select User") to the top before I pass it to the drop down list. I've been trying to use the Union but to now avail (it keeps telling me that my object doesn't support the Union method). My code, prior to attempting to inser a row, is very simple.
public SelectList DropDown_Users() { var context = new VivarianDataContext(); var query = from t in context.AspnetUsers select new { t.UserId, t.LastName }; list = new SelectList(query.AsEnumerable(), "UserId", "LastName"); return list; }
Now I try to insert a row and I found this on the internet and it seems to say that his solution will work. But it is filled with syntax errors. [URL]
I tried to implement it using the following code, but it doesn't compile.
public SelectList DropDown_Users() { SelectList list; //get the original data var context = new SQL2005633131VivarianDataContext(); var query = from t in context.AspnetUsers select new { t.UserId, t.LastName }; //create a dummy table with an empty row var AllUsers = new List<AspnetUsers>(); var BlankUser = new AspnetUsers() {UserId=System.Guid.Empty, LastName="Select One"}; AllUsers.Add(BlankUser); //use Union to join the data - ERRORS HERE var newTable = AllUsers.Union(query); list = new SelectList(newTable.AsEnumerable(), "UserId", "LastName"); return list; }
I have a stored procedure which is part of the aspnetdb but i am using my own database and therefore these stored procedures are added on my sql server locally.So i uploaded the databases to my hosting company 1and1 and created the stored procedures and tables as those in aspnetdb but i get the error as in the title. this is a standard stored procedure which lives in the aspnetdb database but not sure why this is happeningthe code is below which is for aspnet membership createuser a standard stored procedure
I tried nested ListViews but can get the display wanted.In my database I have a Category Table and a Product table.They share the CG_ID value.I want to make a stored procedure that will use two select statements to produce a single table.that can be used as a ListView DataSource.
Before I get too far down the road I just want some advice. I'm building a web app using VWD2008 and MySQL 5. I've got the membership provider stuff working fine and have an odbc connection setup which works "fine". what I've noticed is that when I configure a new sqldatasource (that will be used to provide data to a listview or something) the Advanced -> generate Insert,Update..... option is disabled. I'm assuming its because of the sql syntax difference of the square brackets issue between MS SQL Server and MySQL.
Before I start writing all my own insert and update statements does anyone know if there is a way to get MySQL and VWD to talk the same language, maybe a different connector or something. I'm using mysql-connector-odbc-3.51.15