日期:2014-05-17  浏览次数:20856 次

大家帮我看看的编码语法没有错误,但是没有达到我要的效果,为什么呢??
private void textBox1_KeyDown(object sender, KeyEventArgs e)

  {
  string con_net = "Data Source=190.190.169.41;User ID=sa;Password=sa;Initial Catalog=DDP-MES-DATA;";
  string sql_nec = "SELECT [IMEI],[MTK_IMEI],[SN] FROM [041101014 IMEI]WHERE [IMEI]=" + "'" + textBox1.Text.Trim() + "'or [MTK_IMEI]=" + "'" + textBox1.Text.Trim() + "'or [SN]=" + "'" + textBox1.Text.Trim() + "'";
   
   
  DataTable dt_nc = new DataTable();
  SqlDataAdapter da_nc = new SqlDataAdapter(sql_nec, con_net);
  da_nc.Fill(dt_nc);
   
  if (e.KeyCode == Keys.Enter) 
  { 

   

  if (dt_nc.Rows.Count == 0 )
  {
  Form2 fm2 = new Form2();
  fm2.ShowDialog();
   
  textBox1.Text = "";
  }
  else 
  {
  textBox2.Focus();
   
  }
private void textBox2_KeyDown(object sender, KeyEventArgs e)
  {
   
  string con_neg = "Data Source=190.190.169.41;User ID=sa;Password=sa;Initial Catalog=DDP-MES-DATA;";
  string sql_neg = "SELECT COUNT(*) FROM [041101014 IMEI] WHERE [IMEI]=" + "'" + textBox1.Text.Trim() + "' and [SN]=" + "'" + textBox2.Text.Trim() + "'or[IMEI]=" + "'" + textBox1.Text.Trim() + "' and[MTK_IMEI]=" + "'" + textBox2.Text.Trim() + "'or[SN]=" + "'" + textBox1.Text.Trim() + "' and[IMEI]=" + "'" + textBox2.Text.Trim() + "'or[SN]=" + "'" + textBox1.Text.Trim() + "' and[MTK_IMEI]=" + "'" + textBox2.Text.Trim() + "'or[MTK_IMEI]=" + "'" + textBox1.Text.Trim() + "' and[SN]=" + "'" + textBox2.Text.Trim() + "'or[MTK_IMEI]=" + "'" + textBox1.Text.Trim() + "' and[IMEI]=" + "'" + textBox2.Text.Trim() + "'"; 
  //这个是我连接的表
  DataTable dt_ng = new DataTable();
  SqlDataAdapter da_ng = new SqlDataAdapter(sql_nef, con_neg);
  da_ng.Fill(dt_ng);

  for (int j = 0; j < dt_PO.Rows.Count; j++)

  if (e.KeyCode == Keys.Enter)
  {
   
   
  if (dt_ng.Rows.Count == 0)//到这不执行了,没有达到我判定的效果,这是因为什么。我现在是分别在textbox1和textbox2中输入两个数字,看是不是在同一行,我判定是在textbox2下判定的
  {
  textBox1.Text = "";
  textBox2.Text = "";
  Form2 fm2 = new Form2();
  fm2.ShowDialog();
  System.Media.SoundPlayer sndPlayer = new
  System.Media.SoundPlayer(Application.StartupPath + @"/bad.wav");
  sndPlayer.Play();
  }
  else
   
  {
   
  textBox1.Text = "";
  textBox2.Text = "";
  textBox1.Focus();
   

  }
这段