I am trying to execute a sql server stored procedure from a c# windows app. I need to send it 3 parameters, is this the correct way to do that or am taking the long route.
any feedback greatly appreciated!
Thanks
any feedback greatly appreciated!
Thanks
Code:
private void btnUpdate_Click(object sender, System.EventArgs e)
{
try
{
string strConnection = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection cnn = new SqlConnection(strConnection);
SqlCommand objCommand = new SqlCommand("usp_InsertSoftware", cnn);
objCommand.CommandType = CommandType.StoredProcedure;
SqlParameter objParameter = new SqlParameter("@softwareName",SqlDbType.VarChar, 100);
objCommand.Parameters.Add(objParameter);
objParameter.Direction = ParameterDirection.Input;
objParameter.Value = this.txtSoftware.Text;
SqlParameter objParameter1 = new SqlParameter("@binderID",SqlDbType.Int);
objCommand.Parameters.Add(objParameter);
objParameter1.Direction = ParameterDirection.Input;
objParameter1.Value = this.cboBinders.SelectedValue;
SqlParameter objParameter2 = new SqlParameter("@subscriptionID",SqlDbType.Int);
objCommand.Parameters.Add(objParameter2);
objParameter2.Direction = ParameterDirection.Input;
objParameter2.Value = this.cboSubscriptions.SelectedValue;
cnn.Open();
objCommand.ExecuteScalar();
MessageBox.Show("Software has been added");
cboSoftware.DataSource= null;
bindSoftware();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
//clean up
}
}