I'm getting an similar error in the screenshot below. My question is; when I attempt to write to table those informations inside of textboxes,that's gives me error.Where I wrong? By the way,I'm using SQL Server Express 2008.
private void btnprnsave_Click(object sender, EventArgs e)
{
SqlConnection conn = DBConfigs.DataCon();
SqlCommand record = new SqlCommand ("insert into dbo.PersonalInformationTable (PersonalName,PersonalSurname,PersonalEGN) values ("+txtPrnName.Text+","+txtPrnSurName.Text+","+txtPrnEgn.Text+")", conn);
record.ExecuteNonQuery();
conn.Close();
}
It's a bit hard to tell, but it looks like you need to escape your values in the insert statement.
Format properly your SQL (single quotes around tesxtual values or use parameters)
Chekc if the database file exists.
Do not attach the database file at the same time with SQL Server Management Studio Express as you can't attach the same database file to twice to two different SQL Server (Express) instances.
Always make sure you close the database connection. This shouls be achieved with the using statement as regardless how that block of code is left (exception or normal program flow) the Dispose() method will be called. This will always close the connection, and you have avoided a connection leak.
You need to put single quotes around the textual values in your query. Even better; use parameters...
The exception you get might be caused by something else, but the query in itself is not correct, as stated above...