我的gridview中的“对象引用未设置为对象的实例”

时间:2017-12-28 12:20:17

标签: c# ms-access

我能做什么...我通过搜索谷歌尝试了很多代码,但失败了......请帮助我

protected void RegistrationDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int stdid = Convert.ToInt32(RegistrationDetails.DataKeys[e.RowIndex].Value.ToString());
        int stdroll = Convert.ToInt32(RegistrationDetails.DataKeys[e.RowIndex].Value.ToString());
        int clsid = Convert.ToInt32(RegistrationDetails.DataKeys[e.RowIndex].Value.ToString());
        //DateTime tdob = Convert.ToDateTime(RegistrationDetails.DataKeys[e.RowIndex].Value);
        int vyear = Convert.ToInt32(RegistrationDetails.DataKeys[e.RowIndex].Value.ToString());
        //DateTime vadmdate = Convert.ToDateTime(RegistrationDetails.DataKeys[e.RowIndex].Value);
        GridViewRow row = (GridViewRow)RegistrationDetails.Rows[e.RowIndex]; 
        Label lblID = (Label)RegistrationDetails.Rows[e.RowIndex].FindControl("lblID");
        //TextBox txtname=(TextBox)gr.cell[].control[];  
        //TextBox tid = RegistrationDetails.Rows[e.RowIndex].Cells[0].Controls[0] as TextBox;
        //TextBox troll = RegistrationDetails.Rows[e.RowIndex].Cells[1].Controls[0] as TextBox;
        TextBox tname = RegistrationDetails.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox;
        TextBox tdob = RegistrationDetails.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox;
        TextBox taddress = RegistrationDetails.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox;
        TextBox tcontactp = RegistrationDetails.Rows[e.RowIndex].Cells[6].Controls[0] as TextBox;
        TextBox tgender = RegistrationDetails.Rows[e.RowIndex].Cells[7].Controls[0] as TextBox;
        TextBox tmobile = RegistrationDetails.Rows[e.RowIndex].Cells[8].Controls[0] as TextBox;
        //TextBox tyear = RegistrationDetails.Rows[e.RowIndex].Cells[8].Controls[0] as TextBox;
        TextBox tjdate = RegistrationDetails.Rows[e.RowIndex].Cells[10].Controls[0] as TextBox;
        TextBox tpass = RegistrationDetails.Rows[e.RowIndex].Cells[11].Controls[0] as TextBox;
        //TextBox tclsid = RegistrationDetails.Rows[e.RowIndex].Cells[11].Controls[0] as TextBox;
        TextBox tsecid = RegistrationDetails.Rows[e.RowIndex].Cells[12].Controls[0] as TextBox;

        //string vfullname = fullname.Text;
        //string vaddress = address.Text;
        //string vcperson = cperson.Text;
        //string vmobile = mobile.Text;
        //string vpass = pass.Text;
        //TextBox textadd = (TextBox)row.FindControl("txtadd");  
        //TextBox textc = (TextBox)row.FindControl("txtc");  
        RegistrationDetails.EditIndex = -1;
        con.Open();
        //SqlCommand cmd = new SqlCommand("SELECT * FROM detail", conn);  
        OleDbCommand cmd = new OleDbCommand("update registration set Roll=" + stdroll + ", Full_Name='" + tname.Text + "', Date_of_Birth='" + tdob.Text + "',Address='" + taddress.Text.Trim() + "', Contact_Person='" + tcontactp.Text + "', Gender='" + tgender.Text + "', Mobile='" + tmobile.Text + "', CYear=" + vyear + ", Joining_Date='" + tjdate.Text + "', UPassword='" + tpass.Text + "', Class_ID=" + clsid + ", Section_ID='" + tsecid.Text + "' where Student_ID=" + stdid + "", con);
        cmd.ExecuteNonQuery();
        con.Close();
        refreshdata();
    }

1 个答案:

答案 0 :(得分:0)

对于一个开始,您没有对任何变量赋值进行空检查。

我的猜测是你试图施放的一个牢房是空的。

相关问题