How to save data (easy way)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi

i have a data grid (i fill when i run the program) then the user insert rows
and i wana save..

i used SqlClient.SqlCommandBuilder but it fail, just save 1 recordr, some
times 2 records, sometimes no one record

in the past (my old job) i do it easy whit Delphi or C but i don't find the
easy way to do this in a easy way.

can you help me?
 
thks,

It is hard to answer this question when you do not describe something more
when it does not save it and when it does.

Mostly is it because that the data is saved in the datasource when there is
a rowchange done in the datagrid.

That you can force by using the method endcurrentedit

Something as
BindingContext(ds.Tables(0)).EndCurrentEdit()

where in this sampel ds.tables(0) stands for your datasource

I hope this helps?

Cor
 
Tnks Cor...

(sorry for my english)
dim sqlcon as new sqlconnection(conectionstring)
Dim Sqladapt As new SqlDataAdapter("select * from oc_header", sqlcon)
Dim dsOC As New DataSet
Dim dt As New DataTable
sqlcon.open()
Sqladapt.Fill(dsOC, "Compras")
dt = dsOC.Tables("Compras")
DgResumen.DataSource = dsOC.Tables("Compras") 'dgresumen is a data grid

'this works fine.. but the user insert some rows into the datagrid, then
when the user finish, press the "save" button..

in the save button have this code.

Dim command_builder As SqlClient.SqlCommandBuilder
If dsOC.HasChanges Then
command_builder = New SqlClient.SqlCommandBuilder(sqladapt)
Try
sqladapt.Update(dsOC, "Compras")
Catch ex As System.Exception
MessageBox.Show(ex.ToString)
Catch exSQl As SqlClient.SqlException
MessageBox.Show(exSQl.ToString)
End Try
End If

but don't save all the new records (rows) added some times the user add 3
rows and the save procedure just save 1 or 2, i know i'am new in vb net, and
really dont know what i'am doing wrong.

tnks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top