テキストボックスにIDを入力して押すと、プライベートSQLサーバーデータベースに移動し、そのIDを参照するデータ行を取得する検索ボタンを作成しようとしていますが、例外ハンドラーは私のせいでエラーをもたらします間違った CommandText ..これが私のコードです
private void SearchBtn_Click(object sender, EventArgs e)
{
cn.ConnectionString = Properties.Settings.Default.ConStr;
if (ID.Text == "")
{
MessageBox.Show("Please Enter The ID you would like to search");
}
else
{
SqlCommand com = new SqlCommand();
cn.Open();
SqlParameter user = new SqlParameter("@ID", SqlDbType.Int);
SqlParameter FN = new SqlParameter("@First_Name",SqlDbType.NChar);
SqlParameter LN = new SqlParameter("@Last_Name", SqlDbType.VarChar);
SqlParameter Jb = new SqlParameter("@Job", SqlDbType.VarChar);
SqlParameter Ag = new SqlParameter("@Age", SqlDbType.VarChar);
SqlParameter ph = new SqlParameter("@Phone", SqlDbType.VarChar);
com.Parameters.Add(user);
com.Parameters.Add(FN);
com.Parameters.Add(LN);
com.Parameters.Add(Jb);
com.Parameters.Add(Ag);
com.Parameters.Add(ph);
com.Connection = cn;
これが私のエラーです: *com.CommandText = "Search (First_Name,Last_Name,Job,Age,Phone) values('" + FN + "','" + LN + "','" + Jb+ "','" + Ag + "','" + ph + "' MyList から) ";*
user.Direction = ParameterDirection.Input;
FN.Direction = ParameterDirection.Output;
LN.Direction = ParameterDirection.Output;
Jb.Direction = ParameterDirection.Output;
Ag.Direction = ParameterDirection.Output;
ph.Direction = ParameterDirection.Output;
FN.Size = 10;
LN.Size = 10;
Jb.Size = 10;
Ag.Size = 10;
ph.Size = 10;
user.Value = Convert.ToInt32(ID.Text);
try
{
com.ExecuteNonQuery();
FirstName.Text = FN.Value.ToString();
LastName.Text = LN.Value.ToString();
Job.Text = Jb.Value.ToString();
Age.Text = Ag.Value.ToString();
Phone.Text = ph.Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}
Visual Studio 2012 を使用しています。前もって感謝します 。