title: How to check if column value is null before inserting data from text box
body: <p>I am trying to insert data from text box to sql database, but I want to check if the row is empty then insert new value else update the row with the values with sqlcommands in if else condition.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>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.SqlClient;
  
  
  public partial class CM : System.Web.UI.Page
  {
      DataSet ds = new DataSet();
      SqlDataAdapter da;
      SqlCommand cmd;
      //DataTable dt;
      SqlConnection con = new SqlConnection("server =consulting76\\SQLEXPRESS; database = msdb; Integrated Security=True");
  
      protected void Page_Load(object sender, EventArgs e)
      {
          da = new SqlDataAdapter();
          //("Select * from NOTESMAKER", con);
          //da.Fill(ds, "NOTESMAKER");
          //dt = ds.Tables["NOTESMAKER"];
      }
  
      protected void Button1_Click(object sender, EventArgs e)
      {
          con.Open();
          if (DBNull.Value != null)
          {
              cmd = new SqlCommand("Insert into NOTESMAKER(NOTESMAKER) Values(@text1)",con);
              cmd.Parameters.Add(new SqlParameter("@text1", SqlDbType.NText)).Value = TextBox1.Text;
              da.InsertCommand = cmd;
              cmd.ExecuteNonQuery();
          }
          else
          {
              cmd = new SqlCommand("Update NOTESMAKER set NOTESMAKER = @text1)",con);
              cmd.Parameters.Add(new SqlParameter("@text1", SqlDbType.NText)).Value = TextBox1.Text;
              da.UpdateCommand = cmd;
              cmd.ExecuteNonQuery();
          }
          con.Close();
      }
  
  }
  </code></pre>