首页 新闻 会员 周边 捐助

帮我看看问题?

0
悬赏园豆:20 [已关闭问题] 关闭于 2015-02-02 12:12

private void button1_Click(object sender, EventArgs e)  

      {             string text_ID=null;            

                 string text_name=null;          

                  string text_sdept=null;          

                 string text_sex=null;            

                  int index=0;          

   if (textBox1.Text != null)           

  {             

    ++index;                    

        }          

   if (textBox2 != null)     

        {                 ++index;

         }           

  if (textBox3.Text != null)     

        {                 ++index;   

          }     

        if (radioButton1.Checked = true)      

         {                 ++index;    

         }

            else          

           {                 ++index;     

           }

            if (index < 4)          

             {               

                MessageBox.Show("请填写完整");      

             }      

       else      

       {   string sq = " Data Sourse=localhost; Initial Catalog=zyf_student; User ID=sa; pwd =zyf";  

SqlConnection conn = new SqlConnection(sq);        

         try {

                    conn.Open();                    

SqlCommand com = new SqlCommand();                     com.CommandText = "select sno ,sname,sdept,sex  from     student    where sno ='" + text_ID + "'";      

          dataGridView1.DataSource = com.ExecuteNonQuery();  //本意是点击button实现查询,显示数据放在DATAGRIDVIEW                     

       }                

catch (SqlException ex)             

       {

              MessageBox.Show("数据异常");

        }              

   conn.Close();       

      }      

   }//现在的问题是我什么都没填写  datagridview 已经有结果了

问题补充:

程序开始运行就有了结果,与本意不符

字节跳动的主页 字节跳动 | 初学一级 | 园豆:181
提问于:2015-01-31 19:14
< >
分享
所有回答(3)
0

很简单,null和空字符串是不一样的,

一叶兰舟飘 | 园豆:351 (菜鸟二级) | 2015-01-31 21:36
0

button1

textBox1

textBox2

textBox3

radiobox1

dataGridView1

我也是醉了...

爱编程的大叔 | 园豆:30844 (高人七级) | 2015-01-31 21:38
0

textBox1.Text != null 换成 

String.IsNullOrEmpty(textBox1.Text)

nicky0227 | 园豆:1069 (小虾三级) | 2015-02-01 13:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册