Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27230

VS 2005 Vb.Net Error..Plz help..

$
0
0
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

Viewing all articles
Browse latest Browse all 27230

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>