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...

Recommended Answers

All 5 Replies

Declare that variable in SQL Server.

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

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.

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

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.

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"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.