int no = FormView1.PageIndex;
询问:-
SqlCommand cmd = new SqlCommand("select Answer from Questions where QuestionNo = @no", cn);
您必须添加一个参数:
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;
您需要添加SqlParameter
一个SqlCommand
:
int no = FormView1.PageIndex;
SqlCommand cmd = new SqlCommand("select Answer from Questions where QuestionNo = @no", cn);
cmd.Parameters.AddWithValue("@no", no);
Use SqlParameters. See the example below.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx
使用 System.Data.SqlClient.SqlParameter 数组
SqlCommand cmd(...);
SqlParameter[] inQueryParameters = ...;
cmd.Parameters.AddRange(inQueryParameters);
您可以使用以下代码:
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);
它在我的程序中正常工作。