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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update table via connection object

Status
Not open for further replies.

johnkoutstaal

Programmer
Aug 8, 2006
10
NL
Hello VB net users,

We are trying to update a table with a connection object made in vb dot net

ConnMine is an object made in vb net

Dim strSql As String = "update table set number=0;"
Dim cmd As New OleDb.OleDbCommand(strSql, connMine)
connMine.Open()
cmd.ExecuteReader()

The last line gives an error: an unhandled exception of type "system.data.oledb.oledbException" occurred in system.data.dll

Knows someone a solution to update the table??

Regards,
John.
 
If you are executing SQL that does not return any rows - like an Update - you use the ExecuteNonQuery method of the command object:

cmd.ExecuteNonQuery()

Also, I think you should remove the semi-colon (;) from the end of the SQL.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Hi Jebenson,

Dim strSql As String = "update table set number=0;"
Dim cmd As New OleDb.OleDbCommand(strSql, connMine)
connMine.Open()
cmd.ExecuteNonQuery()

Doesn't work!

Do you have other ideas for updating the table?

John.
 
Is your table actually named "table" and the field to be updated actually named "number"? If so, these may be (probably are) reserved keywords, which would cause an error. Try making the update SQL "update [red][[/red]table[red]][/red] set [red][[/red]number[red]][/red]=0;"

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Hello jebenson,

Thanks a lot, after use the square brackets it's working!!!

John.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top