I'm trying to call a stored procedure from a C# windows Form application. It gets executed but nothing happens up in the database i.e no records are added to the table. Here's my C# code:
private void buttonAddData_Click(object sender, EventArgs e)
{
string actionTaken = "Added";
string changeDescription = "Added new Code";
string updatedBy = "ICherry";
string currentStatus = "In development";
SqlConnection conDatabase = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\ConfigData.mdf;Integrated Security=True;");
try
{
SqlCommand cmd = conDatabase.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "spLogConfigChanges";
cmd.Parameters.AddWithValue("@ActionTaken",actionTaken);
cmd.Parameters.AddWithValue("@ChangeDescription", changeDescription);
cmd.Parameters.AddWithValue("@UpdatedBy", updatedBy);
cmd.Parameters.AddWithValue("@CurrentStatus", currentStatus);
conDatabase.Open();
MessageBox.Show("Connection opened");
cmd.ExecuteNonQuery();
MessageBox.Show("Command Executed");
conDatabase.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
And my SP when executed in Query analyser runs with no errors and I can see the records being created.
Aucun commentaire:
Enregistrer un commentaire