Norwahida Shamsuddin Norwahida Shamsuddin - 1 month ago 15
Vb.net Question

Updating SQL database using VB.net

I try to update database in MS SQL in ASP using VB.NET. This is my code. There is no error but the data in database are not updated

Dim cnConnect As New SqlConnection
cnConnect.ConnectionString = conn.ConnectionString
cnConnect.Open()
Dim cm As New SqlCommand
cm.CommandText = "UPDATE book SET name = '" & name.Text & "'
WHERE idnum = '" & idno.Text & "';"
cm.Connection = cnConnect
cnConnect.Close()

Answer

I think you missed to execute the query. You may have to execute the query before closing the connection like this,

cm.ExecuteNonQuery()
Comments