求大虾解...{"
未将对象引用设置到对象的实例。"}C#.NET
protected override void Modify()
{
DataSet ds = (DataSet)dgv区域.DataSource;
SqlConnection Sqldb连接 = new SqlConnection("Data Source=(local);Initial Catalog=学生成绩2;Integrated Security=True");
Sqldb连接.Open();
SqlCommand sqldb命令 = new SqlCommand("", Sqldb连接);
if (bAdd)
{
sqldb命令.CommandText = "insert into 学生(name,number,scores)values(";
sqldb命令.CommandText += "'" + txt姓名.Text + "',";
sqldb命令.CommandText += "'" + txt学号.Text + "',";
sqldb命令.CommandText += "'" + txt成绩.Text + ",";
DataRow drRow = ds.Tables[dgv区域.DataMember].NewRow();
drRow["name"] = txt姓名.Text;
drRow["number"] = txt学号.Text;
drRow["scores"] = txt成绩.Text;
sqldb命令.CommandText = "select number from" + dgv区域.DataMember + "order by number desc";
drRow["number"] = sqldb命令.ExecuteScalar();
ds.Tables[dgv区域.DataMember].Rows.InsertAt(drRow, 0);
}
else
{
sqldb命令.CommandText = "update 学生 set";
sqldb命令.CommandText += ", name='" + txt姓名.Text + "'";
sqldb命令.CommandText += ", number='" + txt学号.Text + "'";
sqldb命令.CommandText += "'scores='" + txt成绩.Text + "'";
sqldb命令.CommandText += "where number=" + dgv区域.CurrentRow.Cells["number"].Value.ToString();
ds.Tables[dgv区域.DataMember].Rows[dgv区域.CurrentRow.Index]["number"] = txt学号.Text;
ds.Tables[dgv区域.DataMember].Rows[dgv区域.CurrentRow.Index]["name"] = txt姓名.Text;
ds.Tables[dgv区域.DataMember].Rows[dgv区域.CurrentRow.Index]["scores"] = txt成绩.Text;
}
sqldb命令.ExecuteNonQuery();
Sqldb连接.Close();
}
------解决方案--------------------
看看那个为空了再问.不过话又说回来,我很佩服这种"拼"出来的SQL语句.
------解决方案--------------------