PDA

View Full Version : راهنمايي در استفاده از استورد پروسيجر



mehrdad_rabbi
شنبه 14 شهریور 1388, 13:08 عصر
بنده قصد اينزرت در فرم را دارم لطفا راهنمايي فرماييد

كدم:

try
{
sqlConnection1.Open();

sqlCommand1.Parameters.AddWithValue("@name", textBox11.Text);
sqlCommand1.Parameters.AddWithValue("@family", textBox2.Text);
sqlCommand1.Parameters.AddWithValue("@photo",textBox6.Text);
sqlCommand1.Parameters.AddWithValue("@age", textBox7.Text );
sqlCommand1.Parameters.AddWithValue("@carcod",comboBox1.SelectedValue);
sqlCommand1.Parameters.AddWithValue("@carburn", textBox10.Text);
sqlCommand1.Parameters.AddWithValue("@cmelli", textBox1.Text);
sqlCommand1.Parameters.AddWithValue("@mobilenum",textBox3.Text);
sqlCommand1.Parameters.AddWithValue("@phonenum",textBox4.Text);
sqlCommand1.Parameters.AddWithValue("@tahsilat", textBox5.Text);
sqlCommand1.Parameters.AddWithValue("@adress",textBox9.Text);
sqlCommand1.Parameters.AddWithValue("@no", int.Parse(noTextBox.Text));

sqlCommand1.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlConnection1.Close();
}



واین خود رویه :

ALTER PROCEDURE [dbo].[drivers]
@no int,
@name nvarchar(50),
@family nvarchar(50),
@photo nvarchar(max),
@age nvarchar(50),
@cmelli nvarchar(50),
@carcode int,
@carburn nvarchar(50),
@mobilenum nvarchar(50),
@phonenum nvarchar(50),
@tahsilat nvarchar(50),
@adress nvarchar(max)

AS
if not Exists(Select * From driver where no=@no)
begin
Insert into driver ([name],family,photo,age,codemelli,carcode,CarBurnYear,Mo bilenumber,PhoneNumber,Tahsilat,Adress)
values
(@name,@family ,@photo,@age ,@cmelli ,@carcode ,@carburn ,@mobilenum ,@phonenum ,@tahsilat ,@adress)
end




پس از كليك در باتن مربوطه براي اينزرت اين پيام مياد:




PROCEDURE OR FUNCTION DRIVERS HAS TOO MANY ARGUMENTS SPECIFIED

z_bluestar
شنبه 14 شهریور 1388, 16:24 عصر
فكر كنم با اين كد مشكلت حل بشه

sqlConnection1.Open();
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter("name", textBox11.Text);
new SqlParameter("family", textBox2.Text);
new SqlParameter("photo",textBox6.Text);
new SqlParameter("age", textBox7.Text );
new SqlParameter("carcod",comboBox1.SelectedValue);
new SqlParameter("carburn", textBox10.Text);
new SqlParameter("cmelli", textBox1.Text);
new SqlParameter("mobilenum",textBox3.Text);
new SqlParameter("phonenum",textBox4.Text);
new SqlParameter("tahsilat", textBox5.Text);
new SqlParameter("adress",textBox9.Text);
new SqlParameter("no", int.Parse(noTextBox.Text));
};

SqlCommand command = new SqlCommand(storedProcName, sqlConnection1);
command.CommandType = CommandType.StoredProcedure;

foreach (SqlParameter parameter in parameters)
{
command.Parameters.Add(parameter);
}
command.ExecuteNonQuery();