I'm wondering if it's possible to add values to specific Database table cells?
Suppose I have an existing Database table and I add a new value to specific column in a row , how would I go about adding to the new value's column without overwriting the existing columns' rows?
Suppose I have these data for one user I want to insert new phone number to the phone column as it is shown in the image
I searched in google and i found this method
"INSERT INTO Users ( phone ) VALUES('99999975')"
but it gives an error
Cannot insert the value NULL into column 'cardID', column does not allow nulls. INSERT fails.
This is my code:
protected void btnInsert_Click(object sender, EventArgs e)
{
try
{
SqlConnection c = new SqlConnection();
c.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";
string s = "INSERT INTO Users ( phone ) VALUES('99999975')";
SqlCommand sqlcom = new SqlCommand(s, c);
//sqlcom.Parameters.AddWithValue("@phone", TextNum.Text);
c.Open();
SqlDataReader read = sqlcom.ExecuteReader();
while (read.Read())
{
Label3.Text += "name : " + read["name"].ToString() + "<br/>";//start with +=
Label3.Text += "password: " + read["password"].ToString() + "<br/>";
Label3.Text += "phone : " + read["phone"].ToString() + "<br/>";
Label3.Text += "email : " + read["email"].ToString() + "<br/><br/>";
Label3.Text += "cardID : " + read["cardID"].ToString() + "<br/><br/>";
}
//sqlcom.ExecuteNonQuery();
Label3.Text = "Insert successful";
read.Close();
//createTable();
c.Close();
}
catch (Exception ee)
{
Label3.Text = ee.Message;
}
}
Any help would be appreciated.