scalar variable

kapila sharma

Member
Joined
Feb 25, 2009
Messages
7
Programming Experience
Beginner
m trying to insert the records in the database from a form i have created in vb.net
the code as follows
Public Sub addaddress()
Dim con As New SqlConnection
con = New SqlConnection(constr)
Dim cmd As SqlCommand
Dim sql1 As String
sql1 = "INSERT INTO Address(EIN_NR, cLocality, cDistrict, cstate, cpincode, plocality," _
+ "pdistrict, pstate, ppincode) values(@ein,@locality,@district,@stae,@pin ," _
+ "@plocal ,@pdis ,@state ,@pinc )"

cmd = New SqlCommand(sql1, con)
con.Open()

cmd.Parameters.AddWithValue("@ein", mEIN())
cmd.Parameters.AddWithValue("@locality", mclocality())
cmd.Parameters.AddWithValue("@district", mcdistrict())
cmd.Parameters.AddWithValue("@stae", mcstate())
cmd.Parameters.AddWithValue("@pin", mpincode())
cmd.Parameters.AddWithValue("@plocal", mplocality())
cmd.Parameters.AddWithValue("@pdis", mpdistrict())
cmd.Parameters.AddWithValue("@state", mcstate())
cmd.Parameters.AddWithValue("@pinc", mpincode()
cmd = New SqlCommand(sql1, con)
cmd.ExecuteNonQuery()
con.Close()

i got error message Must declare the scalar variable "@ein".
 
m trying to insert the records in the database from a form i have created in vb.net
the code as follows
Public Sub addaddress()
Dim con As New SqlConnection
con = New SqlConnection(constr)
Dim cmd As SqlCommand
Dim sql1 As String
sql1 = "INSERT INTO Address(EIN_NR, cLocality, cDistrict, cstate, cpincode, plocality," _
+ "pdistrict, pstate, ppincode) values(@ein,@locality,@district,@stae,@pin ," _
+ "@plocal ,@pdis ,@state ,@pinc )"

cmd = New SqlCommand(sql1, con)
con.Open()

cmd.Parameters.AddWithValue("@ein", mEIN())
cmd.Parameters.AddWithValue("@locality", mclocality())
cmd.Parameters.AddWithValue("@district", mcdistrict())
cmd.Parameters.AddWithValue("@stae", mcstate())
cmd.Parameters.AddWithValue("@pin", mpincode())
cmd.Parameters.AddWithValue("@plocal", mplocality())
cmd.Parameters.AddWithValue("@pdis", mpdistrict())
cmd.Parameters.AddWithValue("@state", mcstate())
cmd.Parameters.AddWithValue("@pinc", mpincode()
cmd = New SqlCommand(sql1, con)
cmd.ExecuteNonQuery()
con.Close()

i got error message Must declare the scalar variable "@ein".

You set up the command, then destroy everything you have done by making a new command.

Read the DW2 link in my signature, section Creating a Simple Data App - youre making your life much harder than it needs to be
 

Similar threads

Back
Top