0

iam working on project in asp.net using c#....
iam getting this error when iam inserting value from form to database...

Incorrect syntax near 'nvarchar'.
Must declare the scalar variable "@Occupation"...

how to remove this error...
plz reply...

5
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by Sarama2030
0

Declare that variable in SQL Server.

While passing from your form, cast it to it's datatype if it's not in that form.

0

Actually it seems there is a problem in ur storprocedure plz share ur store procedure for quick reply i think u ve not declare variable in ur storeprocedure.

0

cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "UPDATE [advertisement] SET approve = 'true' WHERE id = GridView1.SelectedRow.Cells[0].Text ";
cn.Open();
cmd.ExecuteNonQuery();

0

add a paramaeter to the parameter collection and assign the value of the form to that parameter. then set the parameter as the upadate value in your update statement.

0

code in vb 'kindly

dim z as new data.sqlclint.sqlcommand()
dim k as new data.sqlclient.sqlparameter()

k.parametername="@advert value"
k.direction=parameterdirection.input
k.sqldbtype=sqldbtype.nvarchar
k.value=formfield.value
z.parameters.add(k)

'your update statement should look something like

z.commandtype=commandtype.text
z.comandtext="UPDATE advertisement SET advertvalue=@advert_value WHERE your criteria"

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.