本帖最后由 蔓越莓 于 2013-6-17 21:23 编辑
用ExecuteReader()在逐条查FName的时候,有一个是Null,就报错了。这要怎么处理?- private void button1_Click(object sender,
- RoutedEventArgs e)
- {
- using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=mydb2;User ID=sa;Password=123456"))
- {
- conn.Open();
- using (SqlCommand cmd = conn.CreateCommand())
- {
- cmd.CommandText = "select * from T_employee where FAge<100";
- using (SqlDataReader reader = cmd.ExecuteReader())
- {
- while(reader.Read())
- {
- string name=reader.GetString(1);
- MessageBox.Show(name);
- }
-
- }
- }
- MessageBox.Show("execute accomplish");
- }
- }
复制代码 |
|