I am trying to create an application. One of the task is
to insert a row into a DB. I am using db express 5 with visual studio
8. It feels like I have done everthing under the sun, but still to no avail. I know I'm missing something somewhere I just
can't get it...so I don't spend the rest of my life on this...can someone please assist me..This is a local application and not web based...although that may follow. Thanks
Here is the connection, insert part below:
private void button3_Click(object sender, EventArgs e)
{
{ //Inserting records in the Database Data Source
String ScreenShotConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=ScreenShot;Workstation ID=DLDw5hdc1;Integrated Security=True";
{
//Getting Connection Together
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection(ScreenShotConnectionString);
sqlConnection1.Open();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.Connection = sqlConnection1;
cmd.CommandType = System.Data.CommandType.Text;
// Create the InsertCommand.
cmd = new SqlCommand(
"INSERT INTO Table_1 (ScreenShotNumber, TestScriptID, StepNumber, TesterInitials, Date, DocumentNumber) " +
"VALUES (@ScreenShotNumber, @TestScriptID, @TesterInitials, @Date, @DocumentNumber) ", sqlConnection1);
// Add the parameters for the InsertCommand.
cmd.Parameters.Add("@ScreenShotNumber", SqlDbType.NVarChar, 50, "ScreenShotNumber");
cmd.Parameters.Add("@TestScriptID", SqlDbType.NVarChar, 50, "TestScriptID");
cmd.Parameters.Add("@StepNumber", SqlDbType.NVarChar, 50, "StepNumber");
cmd.Parameters.Add("@TesterInitials", SqlDbType.NVarChar, 50, "TesterInitials");
cmd.Parameters.Add("@Date", SqlDbType.NVarChar, 50, "Date");
cmd.Parameters.Add("@DocumentNumber", SqlDbType.NVarChar, 50, "DocumentNumber");
try
{
//open the connection to the database
}
catch (ConfigurationErrorsException ex)
{
MessageBox.Show("Error in connection ..." + ex.Message);
}
sqlConnection1.Close();
}
}
}