datagridview Help Required please!

frankdaniels

Member
Joined
Jan 27, 2006
Messages
10
Programming Experience
Beginner
Populating a DGV with info from a database is easy. But how on earth do you update the DB with changes to the DGV?? Programatically that is..........
Any assistance would be greatly appreciated as it might lengthen my lifespa.....lol:p
 
Please post your questions in the appropriate forum. The VS.NET forum is not the most fitting forum for DataGrid questions.

Thank you for helping to keep the VB.NET Forums organized.
 
I'm by no means experienced with the DataGridView.
With that said, I assume you're using VB.Net 2005 since the DGV is new to framework 2. My experience has been to simply drag a dataTable from the DataSources panel to a form after adding a DataSource to the project. All the methods needed to fill dataTables and update the dataBase are generated automatically.
 
Thanks for the reply

Here is the situation. I am populating a DGV with the following code.....

Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
Dim conn As New MySqlConnection
Dim myCommandlead, myCommandref As New MySqlCommand
Dim myAdapterlead, myadapterref As New MySqlDataAdapter
Dim myDatalead, myDataref As New DataTable
Dim SQLlead, SQLref As String
Dim myuser As String
myuser = lblloggedin.Text
SQLlead =
"SELECT p.id,p.name_2 as Forename,p.name_1 as Surname,p.tel1 as Telephone,p.add1 as Address_1,p.add2 as Address_2,p.add3 as Address_3,p.add4 as Address_4,p.postcode as Postcode," _
&
"p.cl_type as Claim_Type,p.notes as Notes,concat(t.agent_forename,' ',t.agent_surname) as Lead_Source from postcode_data p,teams t " _
&
"where p.ld_date = curdate() and t.agent_ID = p.ld_agent and t.claims_manager = " & "'" & myuser & "'"
SQLref = "select r.referral_id,r.cust_title as Title,r.cust_forename as Forename,r.cust_surname as Surname,r.cust_tel_day as Day_Tel,r.cust_tel_eve as Night_Tel,r.cust_add1 as Address_1,r.cust_add2 as Address_2,r.cust_add3 as Address_3,r.cust_postcode as postcode," _
&
"r.claim_type as Claim_Type,r.notes as Notes,concat(t.agent_forename,' ',t.agent_surname) as Lead_Source from referral r,teams t " _
&
"where r.date_referral_taken = curdate() and t.agent_id = r.agent_id and t.claims_manager = " & "'" & myuser & "'"
Debug.Print(SQLlead)
conn =
New MySqlConnection
conn.ConnectionString =
"server=modi;userid=user;password=pword;database=kouse"
Try
conn.Open()
Try
myCommandlead.Connection = conn
myCommandref.connection = conn
myCommandlead.CommandText = SQLlead
myCommandref.CommandText = SQLref
myAdapterlead.SelectCommand = myCommandlead
myadapterref.SelectCommand = myCommandref
myAdapterlead.Fill(myDatalead)
myadapterref.Fill(myDataref)
dgvleads.DataSource = myDatalead
dgvreferral.DataSource = myDataref

'cbousername.DataSource = myData
'cbousername.DisplayMember = "name"
'lblpassword.Text = cbousername.SelectedItem("password")
Catch myerror As MySqlException
MsgBox(
"There Was an Error Reading From the Database ;" & myerror.Message)
End Try
Catch myerror As MySqlException
MsgBox(
"There Was an Error Connecting to the Database ;" & myerror.Message)
Finally
If conn.State <> ConnectionState.Closed Then conn.Close()
End Try
End Sub

Now, when a user changed some info..... how do I update the database???
 
Well I've just recently and finally installed VB.NET 2005 so I'm also only now learning to use the new dataComponents. But as I said, just add a dataSource to the project then drag a dataTable from the DataSources panel to a form and all the code and support files will be created automatically. You can then view that code to see how it's done.
To open the DataSources panel, use the main menu and click 'Data' > 'Show Data Sources (Shift+Alt+D)'
 
excellent!

thanks for the link.... I'll watch all those vids....... how come I can never find stuff like that? I think my browser is working against me....
 
I think that you need Update method, DataAdapter.Update(dataSet, "dataTable")

something like this:

myAdapterlead.Update(NameOfYourDataSet, "myDatalead")
myadapterref.Update(NameOfYourDataSet, "myDataref")
 
Back
Top