I created a database and a table in Microsoft SQL and I want to do some experiments on it with C#. I succesfully connected to my database and I can read the first row on the table too. But when I try to insert or delete some data, even though there are no errors, database is not affected.
Code seems to be correct. I think I need to change some properties about the database but I couldn’t solve it. Im 100% sure that there are no connection errors because read function is working. Maybe my database is closed to modify but I do not know how to solve it. Here is my code:
private void button1_Click(object sender, EventArgs e)
{
//1- address of sql server and database
string connection_string = "Data Source=LAPTOP-EC01498K\SQLEXPRESS;Initial Catalog=DENIZDB;Integrated Security=True;Encrypt=True;Trust Server Certificate=True";
//2- create a new connection to that server
SqlConnection con = new SqlConnection(connection_string);
//3- open connection
con.Open();
if (IsConnectionAvailable(connection_string))
{
MessageBox.Show("Connection is formed!");
}
//4- prepare query
string mail = textBox1.Text;
string uname = textBox2.Text;
string pword = textBox3.Text;
string query = "INSERT INTO logging (email, userName, pword) VALUES ('[email protected]', 'tempName', 'password1425')";
//5- execute query
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
//6- close connection
con.Close();
MessageBox.Show("Successfully signed!");
}