I want to do a very simple INSERT INTO
operation, but nothing happens. I see no errors and also I see no changes in the database.
I suspect my connection string is wrong, but how can I know that? If so how can I fix it? (local host)
protected void RegButton_Click(object sender, EventArgs e)
{
string connString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Bodin\\Desktop\\FullFart\\App_Data\\database.mdf;Integrated Security=True;User Instance=True";
string sql = "INSERT INTO student (navn, etternavn) " + "VALUES('" + NavnTextBox.Text + "', '" + EtterNavnTextBox.Text + "');";
SqlConnection conn = new SqlConnection(connString);
SqlCommand myCommand = new SqlCommand(sql,conn);
try
{
conn.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex);
}
finally
{
conn.Close();
}
}
Any ideas why the above code does nothing? (It should add new rows every time executed)
Update
Related to SQL injection. This is a demo program for some homework, that is why i don't use parameters. It is my friends laptop and i only have installed Visual studion 2008 and SQL server 2005. I don't have any other gadgets I can manually add values to the database from visual studio, so that means the DB works. But how can i correctly configure the connection String?