Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, i have a database with SQL server 2014. I made a stored procedure that selects several fields. Until then everything is fine. it returns a datatable that I bind with my datagridview. The problems is when i want to update that datatable. I made an other stored procedure for the update. (My update work fine in sql server). For some reasons when I do the update from visual basic, he did update my dataset but not my database! For a reason x, it looks like it does not connect to the database.

I know i can use sqlconnection.open() and sqlconnection.close() but im working with the "Disconnected Ado.net" so when i call the "updatecommand", it's supposed to connect directly to the database! But it didn't! What am i doing wrong?

Ps: Sorry for my bad english.

Here is a part of my code:

What I have tried:

VB
'Initialize my command
command.CommandType = CommandType.StoredProcedure

command.CommandText = "dbo.update"


command.Parameters.Add(New SqlParameter("@idInventory", SqlDbType.Int, 1, table.Columns(0).Caption))



command.Parameters.Add(New SqlParameter("@idProduct", SqlDbType.Int, 1,    table.Columns(1).Caption))


command.Parameters.Add(New SqlParameter("@code", SqlDbType.NVarChar))
command.Parameters("@code").SourceColumn = "code"

command.Connection = adaptater.Connection
Try
    adaptater.Adapter.UpdateCommand = command
Catch ex As Exception
    MsgBox(ex.Message)
End Try
Posted
Updated 14-Nov-16 7:02am
v2

1 solution

Quote:

command.Connection = adaptater.Connection
Try
    adaptater.Adapter.UpdateCommand = command
Catch ex As Exception
    MsgBox(ex.Message)
End Try

Well, there's your problem. You've assigned the command to the adapter's UpdateCommand property, but you've never told the adapter to update anything!

You need to call the adapter's Update method, passing in the DataSet that you want to update. You might also need to initialize the adapter's InsertCommand and DeleteCommand properties, depending on whether you allow the user to create new rows and delete existing rows.

Updating Data Sources with DataAdapters[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900