偶做了一个关于dataGridView_CellValueChanged事件的代码,但里面有一个关于空值的处理始终不得其所……
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
string connection = "server=192.100.3.3;database=AIS20090330165131;uid=sa;pwd=;";
SqlConnection thisconection = new SqlConnection(connection);
SqlCommand cmd = thisconection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "t_StoreAndSale";
cmd.CommandTimeout = 0;
SqlParameter myParameter = new SqlParameter("@FFullNumber", SqlDbType.VarChar, 40);
myParameter.Direction = System.Data.ParameterDirection.Input;
myParameter.Value = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString().Trim();
cmd.Parameters.Add(myParameter);
SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = cmd;
DataSet ds = new DataSet();
Adapter.Fill(ds);
//问题所在:如果在SQL数据库里,“当日实入”到“AI结存”这10列都是空值,就是说在数据库里根本没有值,连Null值都不是,图片如下,当输入相应的物料代码,就会报“在位置0处没有任何行”,这样的问题如何解?请版主指点
.jpg&mid=1257476726.81761.0.mail234-221.sinamail.sina.com.cn&fid=new&content_type=image/jpeg&attinfo=4-14726-51656-base64&get_cmd=show)
dataGridView1.Rows[e.RowIndex].Cells[1].Value = ds.Tables[0].Rows[0]["当日实入"];
dataGridView1.Rows[e.RowIndex].Cells[2].Value = ds.Tables[0].Rows[0]["当月实入"];
dataGridView1.Rows[e.RowIndex].Cells[3].Value = ds.Tables[0].Rows[0]["当日出货"];
dataGridView1.Rows[e.RowIndex].Cells[4].Value = ds.Tables[0].Rows[0]["当月出货"];
dataGridView1.Rows[e.RowIndex].Cells[5].Value = ds.Tables[0].Rows[0]["包装成品库存"];
dataGridView1.Rows[e.RowIndex].Cells[6].Value = ds.Tables[0].Rows[0]["成品库存"];
dataGridView1.Rows[e.RowIndex].Cells[7].Value = ds.Tables[0].Rows[0]["半成品库存"];
dataGridView1.Rows[e.RowIndex].Cells[8].Value = ds.Tables[0].Rows[0]["包装投结存"];
dataGridView1.Rows[e.RowIndex].Cells[9].Value = ds.Tables[0].Rows[0]["装配结存"];
dataGridView1.Rows[e.RowIndex].Cells[10].Value = ds.Tables[0].Rows[0]["AI结存"];
}