Joma Alrzini

Joma Alrzini

  • NA
  • 61
  • 29.4k

How to stop button from insert empty value

Jul 5 2016 9:23 AM
I need to nut insert empty value to table I tried but I could not even the column is defined not null but it still accept empty value please help 
 this is my code  please help 

protected void btnIdea_Click(object sender, EventArgs e)

{

if (txtContent.Text != null)

// Label7.Text = "Please select User Role";

//else

{

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);


SqlCommand insert = new SqlCommand("insert into dbo.Comments(Comment, UId, IssueDate, MaID, UserName) values(@Comment, @UId, @IssueDate, @MaID, @UserName)", conn);

int id = Int32.Parse(Request.QueryString["Id"]);

insert.Parameters.AddWithValue("@Comment", txtContent.Text);

insert.Parameters.AddWithValue("@UId", Session["UniID"].ToString());

insert.Parameters.AddWithValue("@UserName", Session["Full_Name"].ToString());

insert.Parameters.AddWithValue("@MaID", id);

insert.Parameters.AddWithValue("@IssueDate", DateTime.Now);

try

{

conn.Open();

insert.ExecuteNonQuery();

txtContent.Text = "";

// Response.Redirect("ACourseManagement.aspx");

}

catch

{

Label7.Visible = false;

Label7.Text = "Error when saving on database";

conn.Close();

}

}


}


 

Answers (4)