hello,all,I want to insert textbox vaues to sql table ItemListDB.I have written the code below.After running the program, the following error is showing,"Object Reference not set to an instance of an object ".I am totally new to to this.Plz help me .its urgent.
Dim sql As New SqlCommand
'Dim sql As String
Dim con As New SqlConnection("Data Source=V-PC\WINCCPLUSMIG;Initial Catalog=ProductDB;Integrated Security=True")
Try
sql.CommandText = "INSERT INTO ItemListDB(ItemCode,ItemName,Cost,Price) Values(@ItemCode,@ItemName,@Cost,@Price)"
con.Open()
sql.Parameters.AddWithValue("@ItemCode", Me.txtitemcode.Text)
sql.Parameters.AddWithValue("@ItemName", Me.txtItemName.Text)
sql.Parameters.AddWithValue("@Cost", Me.txtcost.Text)
sql.Parameters.AddWithValue("@Price", Me.txtprice.Text)
"
sql.Prepare()
sql.ExecuteNonQuery()
MessageBox.Show("New Item Added..!!")
Catch ex As Exception
MessageBox.Show("Item could not be added!" & ex.Message)
Finally
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
Dim sql As New SqlCommand
'Dim sql As String
Dim con As New SqlConnection("Data Source=V-PC\WINCCPLUSMIG;Initial Catalog=ProductDB;Integrated Security=True")
Try
sql.CommandText = "INSERT INTO ItemListDB(ItemCode,ItemName,Cost,Price) Values(@ItemCode,@ItemName,@Cost,@Price)"
con.Open()
sql.Parameters.AddWithValue("@ItemCode", Me.txtitemcode.Text)
sql.Parameters.AddWithValue("@ItemName", Me.txtItemName.Text)
sql.Parameters.AddWithValue("@Cost", Me.txtcost.Text)
sql.Parameters.AddWithValue("@Price", Me.txtprice.Text)
"
sql.Prepare()
sql.ExecuteNonQuery()
MessageBox.Show("New Item Added..!!")
Catch ex As Exception
MessageBox.Show("Item could not be added!" & ex.Message)
Finally
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try