2017-07-03 27 views
-1
private void button1_Click(object sender, EventArgs e) 
    { 
     string CS = ConfigurationManager.ConnectionStrings["Test_Evaluate"].ConnectionString; 

     using(SqlConnection con = new SqlConnection(CS)) 
     { 
      SqlCommand cmd = new SqlCommand("select * from Applicant_Details where ApplicantID like @ApplicantID", con); 
      cmd.Parameters.AddWithValue("@ApplicantID", RetrieveRecord_txt + "%"); 
      con.Open(); 
      SqlDataReader rd = cmd.ExecuteReader(); 
      BindingSource source = new BindingSource(); 
      source.DataSource = rd; 
      dataGridView1.DataSource = source; 
     } 
    } 
+2

和錯誤是什麼? – Guy

回答

0

我認爲你的問題是你調用的是ID而不是Text屬性。假設你的表單中包含ID爲 「RetrieveRecord_txt」 的文本框字段,然後:

這樣的: cmd.Parameters.AddWithValue("@ApplicantID", RetrieveRecord_txt + "%");

應該

cmd.Parameters.AddWithValue("@ApplicantID", RetrieveRecord_txt.Text + "%");

相關問題