Note that there are some explanatory texts on larger screens.

plurals
  1. POhaving trouble updating/edit database
    text
    copied!<p>I want to create an application where I can register person info. but I am having a problem updating/edit the data in my gridview. Below is the set of code which I've created.</p> <pre><code>Imports System.Data.SqlClient Public Class Form1 Dim connectionString As String Dim cnn As SqlConnection Dim cmd As SqlCommand Dim sql As String </code></pre> <p>below is my ADD statement and it work just fine</p> <pre><code>Private Sub btnADD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnADD.Click connectionString = "Data Source=XXXX;Initial Catalog=XXXX;User ID=XXXX;Password=XXXX" cnn = New SqlConnection(connectionString) Try cnn.Open() cmd = New SqlCommand("INSERT INTO tbl_info (ID,Name) VALUES (@ID,@Name)") cmd.Connection = cnn With cmd.Parameters .AddWithValue("ID", txtID.Text) .AddWithValue("Name", txtName.Text) End With cmd.ExecuteNonQuery() MsgBox("has been inserted successfully") Catch ex As Exception MsgBox(ex.Message()) End Try txtID.Clear() txtName.Clear() End Sub </code></pre> <p>below is gridview witch is link to my database</p> <pre><code> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'TestDataSet.tbl_info' table. You can move, or remove it, as needed. Me.Tbl_infoTableAdapter.Fill(Me.TestDataSet.tbl_info) End Sub </code></pre> <p>below is my update statement witch i'm having a hard time to figure what is wrong.</p> <pre><code> Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click cnn = New SqlConnection(connectionString) If Not cnn.State = ConnectionState.Open Then cnn.Open() End If Try cmd = New SqlCommand("Update tble_info set Name = @Name Where ID = @ID)") cmd.Connection = cnn With cmd.Parameters .AddWithValue("Name", txtName.Text) .AddWithValue("ID", txtID.Text) End With cmd.ExecuteNonQuery() MsgBox("has been update successfully") Catch ex As Exception MsgBox(ex.Message()) End Try End Sub End Class </code></pre> <p>and this is the error I encountered when I execute the program</p> <pre><code>InvalidOperationExeption was unhadled The connectionString property has not been initialize </code></pre> <p>its pointing to cnn.open()</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload