问题描述
我有上面提到的问题,我希望我能找到解决方案。所以这是错误:
Hi, I have the problem as stated above and i hope that i can found the solution here. So here is the error:
Line 86:
Line 87:
Line 88: if (txtTempIdSubject.Text.Trim() == "")
Line 89: {
Line 90: lblAttention.Text = "Please enter complete data!";
以下是来自.aspx.cs的错误代码:
Here is the code that has the error from .aspx.cs:
protected void dgSubject_ItemCommand(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SubjectClass std = new SubjectClass();
if (e.CommandName == "AddUser")
{
TextBox txtTempIdSubject = (TextBox)e.Item.Cells[0].FindControl("txtSubjectID");
TextBox txtTempNameSubject = (TextBox)e.Item.Cells[1].FindControl("txtSubjectName");
TextBox txtTempModifiedBy = (TextBox)e.Item.Cells[2].FindControl("txtModifiedBy");
TextBox txtTempModifiedOn = (TextBox)e.Item.Cells[3].FindControl("txtModifiedOn");
if (txtTempIdSubject.Text.Trim() == "" )-----> here is the error
{
lblAttention.Text = "Please enter complete data!";
}
else
{
if (std.AddSubject(txtTempIdSubject.Text,txtTempNameSubject.Text, txtTempModifiedBy.Text, txtTempModifiedOn.Text) == false)
{
lblAttention.Text = " *Data addition failed!";
}
else
{
Server.Transfer("Subject.aspx");
}
}
}
这是班级:
and here is the class:
public bool AddSubject(string idSubject,string nameSubject, string modifiedBy, string modifiedOn)
{
try
{
if (this.SetIdSubject(Convert.ToInt32(idSubject)) && this.SetNameSubject(nameSubject) && this.SetModifiedBy(modifiedBy) && this.SetModifiedOn(System.DateTime.Now))
{
DatabaseManager db = new DatabaseManager();
cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO [dbo].[Subjects]" +
"(SubjectID,SubjectName, UpdatedBy, UpdatedOn)" +
"VALUES" +
"(@P1, @P2, @P3,@P4)";
cmd.Parameters.AddWithValue("@P1", this.GetIdSubject());
cmd.Parameters.AddWithValue("@P2", this.GetNameSubject());
cmd.Parameters.AddWithValue("@P2", this.GetModifiedBy());
cmd.Parameters.AddWithValue("@P4", System.DateTime.Now.ToString());
db.ExecuteNonQuery(cmd);
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
我的尝试:
我已将所有Subjects表数据更改为not null因为我发现其中一个解决方案说我需要确保数据不是NULL但它仍然会出现此错误。
What I have tried:
I have changed all the Subjects table data into not null because I found that one of the solutions said that I need to make sure that the data is not in NULL but it still gives this error.
推荐答案
我改变了所有Subjects表数据都不为null,因为我发现其中一个解决方案说我需要确保数据不是NULL,但仍然会出现此错误。
I have changed all the Subjects table data into not null because I found that one of the solutions said that I need to make sure that the data is not in NULL but it still gives this error.
这听起来像你在复制解决方案,但实际上并不知道你在做什么。
在线寻找解决方案也不错如果你知道自己在做什么并且需要提示 - 但是只是对代码进行罚款,并希望他们能够为你想要的任何东西一起工作,这有点愚蠢。依靠在线帮助来弥补学习和理解时间的不足,不会让你长期困扰。
不明白其含义空引用是一个严重的缺点,您应该尽最大努力了解发送给您的各种空错误。
This sounds like you're copying solutions but really haven't any idea what you're doing.
Finding solutions on-line is not a bad thing if you know what you're doing and need a hint - but just fining hunks of code and hoping they'll work together for whatever you think you want is somewhat foolish. Relying on on-line help to make up for a lack of putting in the time to study and understand won't get you far for long.
Not understand the meaning of null references is a serious shortcoming and you should put maximum effort into understand the various null-errors that are sent to you.
这篇关于使用INSERT将数据输入数据库时出现Nullreferenceexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!