sending parameters to Stored Procedure from Form

Oct 5 2010 9:31 AM

hey guys..i am trying to add records to my db...i created stored procedure and it works...but although it can add the datas it show message box and failed because of the if situation i think..but i didnt understand where is my mistake
try
{
con =
new SqlConnection("data source=Erdinc;initial catalog=deneme;integrated security=true");
cmd =
new SqlCommand("sp_TablolaraEkle", con);
con.Open();
cmd.CommandType =
CommandType.StoredProcedure;
cmd.Parameters.Add(
"@marka_ad", System.Data.SqlDbType.NVarChar, 50).Value = textBox1.Text;
cmd.Parameters.Add(
"@model_ad", System.Data.SqlDbType.NVarChar, 50).Value = textBox2.Text;
int rows = cmd.ExecuteNonQuery();
if (rows == 1)
MessageBox.Show("Succeed", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Failed", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
con.Close();
}

Answers (2)