c#改操作时,未将对象引用设置到对象的实例.

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSys... using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Data.OleDb;public partial class update : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { this.Title = "更新记录"; DropNo.AutoPostBack = true; if (!IsPostBack) { OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;" + "Data Source=" + Server.MapPath("App_Data/Student.mdb"); string SqlStr = "select * from grade "; OleDbDataAdapter da = new OleDbDataAdapter(SqlStr, conn); DataTable dt = new DataTable(); da.Fill(dt); DataRow MyRow = dt.Rows[0]; TextName.Text = MyRow["uname"].ToString(); if (MyRow["usex"].ToString() == "男") { RadioSex.SelectedIndex=0; } else { RadioSex.SelectedIndex = 1; } TextClass.Text = MyRow["class"].ToString(); TextMath.Text = MyRow["math"].ToString(); TextChs.Text = MyRow["chs"].ToString(); TextEn.Text = MyRow["en"].ToString(); conn.Close(); } } protected void ButtonSubmit_Click(object sender, EventArgs e) { OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;" + "Data Source=" + Server.MapPath("App_Data/Student.mdb"); string SqlStr = "select * from grade where uid='"+DropNo.Text+"'"; //string SqlUpd = "update grade set uname='" + TextName.Text + "',usex='" + RadioSex.SelectedValue.ToString() + "',class='" + TextClass.Text + "',math=" + int.Parse(TextMath.Text) + ",chs=" + int.Parse(TextChs.Text) + ",en=" + int.Parse(TextEn.Text) + " where uid='" + DropNo.Text + "'"; //OleDbCommand UpdCom = new OleDbCommand(SqlUpd, conn); //OleDbDataAdapter da = new OleDbDataAdapter(); //conn.Open(); //da.UpdateCommand.ExecuteNonQuery(); //conn.Close(); OleDbDataAdapter da = new OleDbDataAdapter(SqlStr, conn); DataTable dt = new DataTable(); OleDbCommandBuilder builder = new OleDbCommandBuilder(); da.Fill(dt); DataRow MyRow = dt.Rows[0]; MyRow[1] = TextName.Text; MyRow[2] = RadioSex.SelectedValue.ToString(); MyRow[3] = TextClass.Text; MyRow[4] = int.Parse(TextMath.Text); MyRow[5] = int.Parse(TextChs.Text); MyRow[6] = int.Parse(TextEn.Text); da.Update(dt); Response.Write("<script language=javascript>alert('记录更新成功,请单击“返回”回到主页面!');</script>"); conn.Close(); } 展开
 我来答
尔离好活笑4
2017-12-31 · TA获得超过2049个赞
知道小有建树答主
回答量:1521
采纳率:87%
帮助的人:204万
展开全部
da放在外面定义时不能赋值。而且你的da里面也没有数据,你都没把查询的结果赋给da。
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式