Hello: I have a windows app created in vb.net 2005.
On my form is a datagridview and I need to save data to my sql database.
This is the first time I'm working with the dgv and so I wanted to know,
if I use the sqldataAdapter, do I still have to loop through each record to save?
In my save right now, I'm trying to get the changes the user made.....and then
try to update the dataadapter; however, it's not happy on this line:
data_adapter.Update(changes)
Maybe I'm not doing it correctly...or I need to be looping through each record?
Thanks,
Luxe
changes is a dataset.
On my form is a datagridview and I need to save data to my sql database.
This is the first time I'm working with the dgv and so I wanted to know,
if I use the sqldataAdapter, do I still have to loop through each record to save?
In my save right now, I'm trying to get the changes the user made.....and then
try to update the dataadapter; however, it's not happy on this line:
data_adapter.Update(changes)
Maybe I'm not doing it correctly...or I need to be looping through each record?
Thanks,
Luxe
VB.NET:
[SIZE=2]changes = ds.GetChanges()
[SIZE=2][COLOR=#0000ff]If [/COLOR][/SIZE][SIZE=2][COLOR=#000000]changes [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]IsNot[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Nothing [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]bolSucess = oService.UpdateJobs_test(changes)
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] if[/SIZE][/SIZE]
changes is a dataset.
VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sql [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"select jobid, jobcreatedby as loginname,jobcreateddate,attachedfilesid, assignedto,assigneddate,AssignedBy,jobduedate,rush,cus.name,signreads,program,hardspec,comments,jobopeneddate,jobstatus,Jobbomstatus,job.custId,TerritoryID, SalesPersonID, Commentsdd from tbljob job,tblcustomer cus where cus.custid= job.custid and jobcommited ='True'"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] data_adapter [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SqlDataAdapter
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] myDS [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] DataSet
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]data_adapter = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SqlDataAdapter(sql, sConnectionString)
data_adapter.Fill(myDS, [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"tbljob"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])
data_adapter.TableMappings.Add([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Table"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"tbljob"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE][SIZE=2]
data_adapter.Update(changes)
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Catch
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"UpdateJobs_test error."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][/COLOR][/SIZE]