2
int no = FormView1.PageIndex;

询问:-

  SqlCommand cmd =  new SqlCommand("select Answer from Questions where QuestionNo = @no", cn);
4

5 回答 5

5

您必须添加一个参数:

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;
于 2013-07-09T16:11:21.690 回答
1

您需要添加SqlParameter一个SqlCommand

int no = FormView1.PageIndex;
SqlCommand cmd = new SqlCommand("select Answer from Questions where QuestionNo = @no", cn);
cmd.Parameters.AddWithValue("@no", no);
于 2013-07-09T16:11:24.340 回答
0

Use SqlParameters. See the example below.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx

于 2013-07-09T16:16:01.967 回答
0

使用 System.Data.SqlClient.SqlParameter 数组

SqlCommand cmd(...);
SqlParameter[] inQueryParameters = ...;
cmd.Parameters.AddRange(inQueryParameters);
于 2013-07-09T16:13:04.750 回答
0

您可以使用以下代码:

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);

它在我的程序中正常工作。

于 2017-03-02T14:36:38.743 回答