Reputation: 21
int no = FormView1.PageIndex;
Query:-
SqlCommand cmd = new SqlCommand("select Answer from Questions where QuestionNo = @no", cn);
Upvotes: 2
Views: 3879
Reputation: 29
You can use this code:
SqlCommand ageCom = new SqlCommand("select age_phase from PatintInfo where patient_ID=@ptn_id", con);
ageCom.Parameters.Add("@ptn_id",SqlDbType.Int).Value=Convert.ToInt32(TextBox1.Text);
It had worked in my program correctly.
Upvotes: 0
Reputation: 1
Use SqlParameters. See the example below.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx
Upvotes: 0
Reputation: 1858
use an array of System.Data.SqlClient.SqlParameter
SqlCommand cmd(...);
SqlParameter[] inQueryParameters = ...;
cmd.Parameters.AddRange(inQueryParameters);
Upvotes: 0
Reputation: 152596
You need to add a SqlParameter
to the SqlCommand
:
int no = FormView1.PageIndex;
SqlCommand cmd = new SqlCommand("select Answer from Questions where QuestionNo = @no", cn);
cmd.Parameters.AddWithValue("@no", no);
Upvotes: 1
Reputation: 564631
You have to add a parameter:
int no = FormView1.PageIndex;
SqlCommand cmd =
new SqlCommand("select Answer from Questions where QuestionNo = @no", cn);
// Set the parameter up before executing the command
cmd.Parameters.Add("@no", SqlDbType.Int);
cmd.Parameters["@no"].Value = no;
Upvotes: 5