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!";
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;
}
}
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.