Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL command builder

Status
Not open for further replies.

BoFenger

Programmer
Aug 6, 2003
22
DK
Hi TT
I have read all about commandbuilder in several NG's but still I can't find out whats wrong
I have a SQL database called "m100SQL" with a table called "m100", below is the code I use to fill a dataset, and update the database, but it fails. Could somebody please tell me what I'm doing wrong
\Bo

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
Dim con As New SqlConnection

Dim PubConn As New SqlConnection("Data Source=(local);Initial Catalog=m100SQL;Integrated Security=SSPI;")
Dim pubCom As New SqlCommand("select * from m100", PubConn)
Dim daPub As New SqlDataAdapter
Dim byg As New SqlCommandBuilder

Dim ds As New DataSet

'*** dataset fill
PubConn.Open() 'open´a dataconnection to the database
daPub.SelectCommand = pubCom
daPub.AcceptChangesDuringFill = False
daPub.Fill(ds, "m100")
PubConn.Close()

ds.AcceptChanges()
ds.Tables("m100").Rows(0)(0) = 50 ' edit the dataset


PubConn.Open()

byg = New SqlCommandBuilder(daPub)

daPub.InsertCommand = byg.GetInsertCommand
daPub.InsertCommand.Connection = PubConn
daPub.UpdateCommand = byg.GetUpdateCommand
daPub.UpdateCommand.Connection = PubConn

daPub.Update(ds, "m100") '*******FAILS HERE WITH SYSTEM ERROR

PubConn.Close()

End Sub
 
It fails here ---- daPub.Update(ds, "m100") '*******FAILS HERE WITH SYSTEM ERROR


because that is where the execution of the statement is.

You need to catch the actual error

Try

'Put your code here

Catch ex as SqlClient.SqlException

Messagebox.show(ex.ToString)

End Try


This will give you a readable error and should show you what is wrong. If you still cannot figure it out the post the error here and I will help you.

DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top