|
-
Oct 4th, 2010, 03:11 AM
#1
Thread Starter
Junior Member
Datagridview
Gud day,
Can any one help me or give me an idea...
I am making a simple program.. i have a Form named frmmain that contained datagridview control named DataGridView1.. and another form named frminsert that contains two textbox controls named txtFname and txtLname and Button control named btinsert.. I want to pass the value from txtFname to the Datagridview column1 and the value of txtLname to the Datagridview column2 when I click the btinsert.
Thank you very I much...
-
Oct 4th, 2010, 03:35 AM
#2
Member
Re: Datagridview
I know this is not a good practice but this may help...
Code:
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
frmmain.DataGridView1.Rows.Add(txtFname.Text, txtLName.Text)
End Sub
-
Oct 4th, 2010, 04:02 AM
#3
Thread Starter
Junior Member
Re: Datagridview
Thanks for the idea... Great!
Now, after inserting the new values into their appropriate fields, I want the Datagridview to create automatically a new row so I can insert the new set of value to the second row and so on from the textboxes. I already set the property of the texboxes to clear after the click event so I can insert new values to it..
Any idea Sir?
Thank you . . .
-
Oct 4th, 2010, 04:07 AM
#4
Member
Re: Datagridview
By default the datagridview should Automatically create a new row when you have added a data...check if your datagridview property AllowUserToAddRows is true...
-
Oct 18th, 2010, 08:41 PM
#5
Thread Starter
Junior Member
Re: Datagridview
Good Day Experts!
Can anyone give me an idea how to insert or save the values in the datagridview to SQL DATABASE?
I’ll just make an example, in my DataGridView I have 4 Columns, Column1 is for ID, Column2 is for Name, and Column3 is for Address. I already created a table in my Database named tblEmployee (Let’s just assumed the name of my database is DATABASE).
For example I have already inserted values in 5 rows in my DataGridView, how can I insert it to my tblEmployee? Don’t worry for the connection string I already configure it.. My problem is the syntax to insert the values to the SQL table.
(Someone told me that I must use a Loop statement)
Thank you for the support.
-
Oct 18th, 2010, 09:51 PM
#6
Re: Datagridview
The most appropriate way to do this would be to create a DataTable and bind it to the grid. You can then use a DataAdapter to save all the data in one go. Follow the Database FAQ link in my signature and check out the .NET section. Amongst others, there's a link there to my own CodeBank thread on Retrieving & Saving Data, which will provide relevant code examples. The only other things you need to know are:
1. To build a DataTable schema without retrieving any data, call FillSchema instead of Fill.
2. To bind a DataTable to a DataGridView, assign the table to the grid's DataSource property.
Also, when you have a DataTable, editing the data in code should be done against the DataTable, not against the DataGridView.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|