C# - Insert Selected Rows Value Of Gridview Into Database?
I am Developing Windows Form Application in .Net, I want to insert selected rows value of Gridview into database. First Column of my GridView is Checkbox, when user check one or more checkbox from gridview, i want to insert values of respective rows into Database. In Web application i done this using DataKeyNames property of GridView. Want to know how to do it in Windows Form Application. I am using Visual Studio 2005.
View 2 Replies (Posted: Apr 21 10 at 5:59)
Sponsored Links:
Related Forum Messages For ASP.NET category:
Forms Data Controls :: Gridview - Insert Multiple Rows Based On Selected Checkbox
I have a gridview object to which I added <asp:TemplateField > <ItemTemplate> <asp:CheckBox ID="chkCopy" OnCheckedChanged="chkStatus_OnCheckedChanged" runat="server" /> </ItemTemplate> </asp:TemplateField> The page count is set to 10, when the user checks the checkbox(es), I will need to insert those records in a table. How will I know which row was selected? I found an example (untried) that is designed to loop through and insert the necessary records; but it does not address inserting records based on selecting rows via a checkbox. How do I put everything together. // open connection mySqlConnection.Open(); //enumerate the items in the list foreach (SPListItem curItem in curItems) { string sql = "INSERT INTO ImportNotifications"; sql += " (SharepointID,Title,WorkOrderNumber,Status,Department,ClientName,WorkOrderDueDate,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Late,LateRe view,TrueLate,Body)"; sql += " VALUES (@ID,@Title,@WorkOrderNum,@Status,@Department,@ClientName,@WorkOrderDue,@Created,@Author,@Modified,@Editor,@Late,@LateReview,@TrueLate,@Bod y)"; mySqlCommand.CommandText = sql; mySqlCommand.Parameters.Clear(); mySqlCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Float)).Value = curItem["ID"]; mySqlCommand.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar, 200)).Value = curItem["Title"].ToString(); mySqlCommand.Parameters.Add(new SqlParameter("@WorkOrderNum", SqlDbType.NVarChar, 50)).Value = curItem["Work_x0020_Order_x0020_Number"].ToString(); mySqlCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.NVarChar, 50)).Value = curItem["Status"].ToString(); mySqlCommand.Parameters.Add(new SqlParameter("@Department", SqlDbType.NVarChar, 100)).Value = curItem["Department"].ToString(); mySqlCommand.Parameters.Add(new SqlParameter("@ClientName", SqlDbType.NVarChar, 255)).Value = curItem["Client_x0020_Name"].ToString(); mySqlCommand.Parameters.Add(new SqlParameter("@WorkOrderDue", SqlDbType.DateTime)).Value = curItem["Work_x0020_Order_x0020_Due_x0020"]; mySqlCommand.Parameters.Add(new SqlParameter("@Created", SqlDbType.DateTime)).Value = curItem["Created"]; mySqlCommand.Parameters.Add(new SqlParameter("@Author", SqlDbType.NVarChar, 50)).Value = curItem["Author"].ToString(); mySqlCommand.Parameters.Add(new SqlParameter("@Modified", SqlDbType.DateTime)).Value = curItem["Modified"]; mySqlCommand.Parameters.Add(new SqlParameter("@Editor", SqlDbType.NVarChar, 50)).Value = curItem["Editor"]; mySqlCommand.Parameters.Add(new SqlParameter("@Late", SqlDbType.NVarChar, 50)).Value = curItem["Late"]; mySqlCommand.Parameters.Add(new SqlParameter("@LateReview", SqlDbType.NVarChar, 50)).Value = curItem["Late_x0020_Review"]; mySqlCommand.Parameters.Add(new SqlParameter("@TrueLate", SqlDbType.NVarChar, 50)).Value = curItem["TrueLate"]; mySqlCommand.Parameters.Add(new SqlParameter("@Body", SqlDbType.NVarChar, -1)).Value = curItem["Body"].ToString(); // execute the command mySqlCommand.ExecuteNonQuery(); } // close the connection mySqlConnection.Close();
Posted: Aug 11, 2010 07:21 PM
View 4 Replies!
View Related
SQL Server :: Insert Large No Of Excel Sheet Rows Into Database Table?
I have an excel sheet that contains around 30,000 rows and 18 colmns. These no of rows and columns may increase in future. I need to read all these records from excel sheet and insert into a table in sql database. For reading the excel book I am using Oledbconnections. The possible solutions I have known as per my knowledge, to insert the data are 1. To insert one record at a time which makes 30,000 database hits. How will this affect the performance? 2. To use liked servers - bu this is not working for me.I do not have database permissions to use linked servers. So, the only option i have is the first one.
Posted: Aug 17, 2010 05:51 AM
View 2 Replies!
View Related
MVC :: Insert Selected Check Box Value And Related Text Box To Database?
I am very new to MVC and I have a Model like this User : FirstName : TextBox LastName : TexBox User Commitee : [CheckBox Textbox] [CheckBox Textbox] [CheckBox Textbox] I store if user is in committee in a separate table.I need to insert selected check box value and related text box to database.How can I achieve this ? Can this be possible with using EditorTemplate ?
Posted: Oct 22, 2010 04:34 PM
View 1 Replies!
View Related
C# - Retrieving The Underlying Dataitems Of Selected Gridview Rows?
I have a button on the page and a gridview with checkboxes on the first column. The gridview is bound to a List. On buttonClick, I need to retrieve the underlying bound data item (MyEntity) for each selected row. How can I do this? I can't simply recreate MyEntity based on the gridview columns, because I am not displaying all the fields of MyEntity. I need a way to get a hold of MyEntity based on the key (MyEntityId).
Posted: Oct 29 10 at 22:01
View 2 Replies!
View Related
Visual Studio 2005 - Extract Rows From DataBase - Replace Fields - Insert Into Another Table
I work with Visual studio 2005 and Sql server data base. I extract 1 million rows from a database and I put the rows in a Sql table. With a simple direct extraction, in a few minutes I complete the operation: Dim cmd As New SqlCommand(query, cnSql) cmd.ExecuteNonQuery() cmd.Dispose(). But, if I must select and modify some fields between extraction and introduction, it takes a lot of time! I work in this way. I extract rows from Dbase, Table1, and I put all into a Collection using dataReader: Dim cmd As New SqlCommand(query, cnSql) Dim coll As New Collection coll.Clear() Dim dr As SqlDataReader = cmd.ExecuteReader() I replace some fields with the string "YES". Dim toRepl As String = "" If dr.HasRows Then Do While dr.Read toRepl = dr(5).ToString If Len(toRepl) <= 3 Then ToRepl = "YES" collPrel.Add(dr(0).ToString) collPrel.Add(dr(1).ToString) .................. .............. collPrel.Add(toRepl) collCount = collCount + 1 Loop End If dr.Close() cmd.Dispose() Now, I insert all into a SQL Table2: Dim a As String = "", b As String = "", c As String = "" etc. For i = 1 To collPrel.Count Step 6 a = collPrel.Item(i).ToString b = collPrel.Item(i + 1).ToString .............. ............... f = collPrel.Item(i + 5).ToString queryIns = "INSERT INTO Tab (name, adress, etc) VALUES ('" & a & "', '" & b & "', '" & c & "', etc. ) Dim cmdIns As New SqlCommand(queryIns, cnSql) cmdIns.CommandTimeout = 600 cmdIns.ExecuteNonQuery() cmdIns.Dispose() Next This way to work goes right but it is necessary a lot of time for completing the operation.
Posted: Mar 08, 2010 10:15 AM
View 1 Replies!
View Related
Forms Data Controls :: GridView Selected Rows Validation?
I want some solution for my gridview to validated only selected rows.What is the senario:In my gridview there are 1 templatecolumn - Total Balance -txtTotalBalanceand1 another templatecolumn - Amount Received -txtAmountReceived There are checkboxes I want to compare only that row which is checked with txtTotalBalance with txtAmountReceived should not be greater than totalbalance.In current code all rows validating compare validator.That I don't want.Please give me solution-If possible then please send me the code also..
Posted: Oct 15, 2010 07:16 AM
View 2 Replies!
View Related
Forms Data Controls :: Get GridView's Selected Rows's Cell Value?
this is my aspx code fro a gridview <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="SubContract_No" ForeColor="#333333" GridLines="None" OnRowDeleting="GridView1_RowDeleting" Width="900px" ShowFooter="True" OnRowEditing="GridView1_RowEditing" > [Code].... Budget_Line is my Gridview's first column How to get this value
Posted: Dec 30, 2009 06:05 AM
View 5 Replies!
View Related
Forms Data Controls :: Insert Rows In GridView On DataBind?
I have a GridView which is databound to a database table. Let's say each record contains a date and the monetary profit for that day. Now here's the problem. Some dates have no record in the table because the store was closed or it's just so shitty that no profit was made. As a result the gridview looks like the following: 10/01/2009 $200 10/02/2009 $250 10/05/2009 $300 10/07/2009 $210 Obviously if there is no record, no row is inserted into the gridview. Instead, I want the gridview to display the results as follows: 10/01/2009 $200 10/02/2009 $250 10/03/2009 $0 10/04/2009 $0 10/05/2009 $300 10/06/2009 $0 10/07/2009 $210 So in other words, when there is no record, I want a row to be inserted into the gridview with the missing date and $0. How would I acheive this? I'm assuming I'll need to use a DataTable and perhaps do some stuff in the DataBind event of the gridview
Posted: Oct 03, 2009 09:45 PM
View 5 Replies!
View Related
Forms Data Controls :: How To Remove Selected Rows From Gridview And List
I m working on MOSS 2007. My project requirment is to fetch the data from list to gridview with check boxes in front of all rows. when we click the checkbox infront of rows then that rows will be move to another gridview & remove from first gridview. Then I have to search the rows by location. following is my code it fetches the list in gridview & move rows from one gridview to anothe 1. how to remove selected rows from gridview & list? how to search by location. [code]....
Posted: Nov 23, 2010 07:00 AM
View 1 Replies!
View Related
Forms Data Controls :: Copy Rows From Gridview Selected Items?
have a page that has a results gridview where I have all rows with a chekbox. when I click on the checkbox I try to create an excel filethis is method content: DataTable MyData = new DataTable(); //recorrido sobre los elementos seleccionados6 foreach (GridViewRow row in gvwDbf.Rows) [code]... The problem is that excel file is totally empty. When I trace on the error I find that (item on bold above) dt datable has current record as I expected but Mydata table has nothing inside. shouldn't I use import statement? How can I get the row copied? I intend to have a full table made by every record coming from parameters of each query which is performed inside a for each sentence
Posted: Apr 01, 2011 04:41 AM
View 1 Replies!
View Related
Forms Data Controls :: Disable Check Box For Selected Rows In Gridview?
I am using two Gridview controls with in a page. Gridview1 contains pending records(on left side). Gridview2 contains Transfer records(on right side). I added check box for both grids. I have two buttons Add & remove Button in between the grids.I loaded the pending records(Gridview1) from my stored proc. By selecting checkbox user can move rows from leftside to right side with add button & rightside to left side with remove button vise versa. Up to this everything works fine. Gridview 2 contain the records which are moved from Gridview 1. In gridview 2 I am binding another table .i,e Records in Process Table from my database. This table has same column name. This table records shows to the user Records which are in process. I want to disable checkboxes for Records in Process Table rows in gridview 2. So that they can't move the records to Gridview1.in which event i should write the code. ??
Posted: Dec 01, 2009 02:50 PM
View 3 Replies!
View Related
Forms Data Controls :: Gridview Concerning Selected Rows And Inline Editing?
Using a gridview with paging, sorting, inline editing, and selection enabled. I noticed the following:1. after selecting a row, then sorting, the selection sticks to the position in the grid, rather than the actual data. I would have expected it to either stick with the data, or clear the selection so nothing is selected. I would just assume clear the selection rather than have it actually change, like it is now. When a row is selected, I'm showing detail information about that specific row below the grid, so when a user does this, then sorts, the selected row changes and the new selected row's detail info shows below the grid. How should I go about stopping this? Hook into the gridview's Sorting event and set the selected row back to -1 (for nothing selected)? I assume that would work but I was compelled to post anyway to see if there is something else I should be doing... 2. I have not tested yet, but I assume the same thing would happen when paging occurs?3. another issue I'm having is when a user enters into edit mode for a row. This also does not clear a previous selection, so if a user had first selected a row, which shows the detail info for that row below the grid, then they hit the edit button for a different row, now on screen at the same time is a selected row (visible by selectedRowStyle), it's detail info below, and a completely different row in edit mode... this is a very confusing scenario for a user. I either need to ensure that any selection is cleared once in edit mode, OR sync these up so that the row in 'edit' mode also becomes the selected row... what do you guys/gals normally do for this situation? I'm thinking syncing up so that the row in edit mode is also selected sounds preferable... how would I do that?
Posted: Dec 18, 2010 09:31 PM
View 2 Replies!
View Related
Forms Data Controls :: Insert Database NULL If Drop Downlist Item Is Not Selected?
on my aspx I have the below DDL <asp:DropDownList ID="ColorDDL" runat="server" DataSourceID="ColorObj" DataTextField="Size" DataValueField="BustId" Width="150px" AppendDataBoundItems="True"> <asp:ListItem Value="-1">(Optional)</asp:ListItem> </asp:DropDownList> If the user does not select an item I get an exception when i call the ObjectDataSource Method and DAL as below to insert into database ProfileObj.InsertParameters["ColorId"].DefaultValue = ColorDDL.SelectedValue.ToString(); What I want to do is insert a database NULL instead.
Posted: Sep 01, 2010 01:05 AM
View 3 Replies!
View Related
Adding Multiple Rows, Displaying Session Rows And Then Doing One Insert?
I need to produce a from where I can add multiple parts. Each time a user enters a part number, the description should be populated. The user can then click add and this part and description will be shown below. They have the option to add as many parts as they require. Once all parts are added the user fills in some general info eg description and then once a submit button is clicked all part info will be inserted into a table and general info will be inserted into another table with one unique ID.
Posted: Apr 14 10
View 5 Replies!
View Related
Validation On CSV File And Insert Rows Of CSV File Into Multiple Tables Of SQLServer Database?
I have to upload a csv file, perform some validations (No of coloumn must be 8, if any cell in Coloumn 2 contains a text "Answer" it must be followed by a "Question" above in same coloum) and then insert the values into database as following 1. worksheet name should be inserted into "tblSection" table database. 2. The rows those contain text "Question" in 2nd coloumn of CSV file will goes into "tblQuestion" table. 3. The rows those contains text "Answer" in 2nd Coloumn should be inserted into "tblAnswer" table of db.
Posted: Aug 12, 2009 03:37 PM
View 1 Replies!
View Related
2 Rows For Each Database Record In A Gridview?
I am working on a web page that will display records from a database. Each record has a total of 8 columns. One column may be as long as 500 characters, and the other 7 columns are between 5 to 25 characters. For each record in the dataset returned from the database, the short columns should be above, and the long column below. In other words, each database record is made of two rows, the 7 short fields in the top row (each field in a cell), and the long field in the bottom row in one cell. Both rows should be similar in length.
Posted: Feb 25 10
View 4 Replies!
View Related
Forms Data Controls :: Limit Number Of Selected Rows In Data Source For GridView?
I'm sure it was discussed hundred of times, but maybe this time will elucidate some new points ) The question is: do I need to limit number of selected rows in data source for GridView? When I use paging in GridView does limiting selected rows make GridView work faster? Now I use ObjectDataSource with Linq in functions. [Code].... Does this make sense or I can just use LinqDataSource without thinking of selected rows?
Posted: Apr 30, 2010 07:56 AM
View 2 Replies!
View Related
|