PDA

View Full Version : سوال: Procedure or function has too many arguments specified in my stored procedureمشکل



hercool
پنج شنبه 31 مرداد 1392, 21:00 عصر
سلام دوستان
من در مرحله ذخیره شدن اطلاعات درون دیتابیس به مشکل خوردم و این پیام رو به من میده
Procedure or function has too many arguments specified in my stored procedure (http://stackoverflow.com/questions/13545995/procedure-or-function-has-too-many-arguments-specified-in-my-stored-procedure)

این کد من هست
public void saveIntraDayPriceData(DataTable x)
{
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand command = new SqlCommand("sp_intraday");
command.Connection = con;
command.Connection.Open();
command.CommandType = CommandType.StoredProcedure;
adapter.SelectCommand = command;
for (int b = 0; b < x.Rows.Count; b++)
{
string ti = x.Rows[b]["time"].ToString();
int tim = ti.IndexOf("&nbsp"); string tima = ti.Substring(tim + 1, ti.Length);
//string tarikh = ti.Substring(1,9);
//string hajm = x.Rows[i]["Transactionvalue"].ToString();
// int noghteh = hajm.IndexOf("."); hajm = hajm.Substring(0, noghteh);
command.Parameters.Add(new SqlParameter("@codecompany", 6422));
command.Parameters.Add(new SqlParameter("@tarikh", 3));
command.Parameters.Add(new SqlParameter("@timee", x.Rows[b]["time"]));
command.Parameters.Add(new SqlParameter("@price", x.Rows[b]["price"]));
command.Parameters.Add(new SqlParameter("@price1", x.Rows[b]["price1"]));
command.Parameters.Add(new SqlParameter("@price2", x.Rows[b]["price2"]));
command.Parameters.Add(new SqlParameter("@price3", x.Rows[b]["price3"]));
command.Parameters.Add(new SqlParameter("@Turnover", x.Rows[b]["Turnover"]));


}command.ExecuteNonQuery();
//command.Connection.Close();
MessageBox.Show("save intradayprice با موفقیت انجام شد");

}


چک کردم که تعداد پارامتر های ارسالی با پارامتر های داخل استوری پروسیجر برابر باشه و مشکلی نبود و تعداد برابر بود یباز این مشکل پا برجاست

هر کاری کردم نشد ممنون میشم راهنماییم کنید چکار کنم این مشکل رفع بشه

nina_rahmani
پنج شنبه 31 مرداد 1392, 21:39 عصر
از پروسیجر تو خود sql یک exec بگیرید با همین پارامترها ببینید اونجا مشکلی ندارید... و پروسیجر اجرا میشه؟

hercool
پنج شنبه 31 مرداد 1392, 21:51 عصر
برای یکی ایراد نمیگیره برای بیشتر از یکی ایراد میگیره
مشکل اینجاست که من مقادیری که میدم رومی تونه تو گرید ویو نشون بده اما نمی تونه همون دیتاتیبل رو بریزه داخل دیتابیس
بیشتر از یک کوئری که میشه ارور میده و این خطا رو میده
فروم ها رو چک کردم یه سری اصلاحات انجام دادم بازم ثمری نداشت

FastCode
پنج شنبه 31 مرداد 1392, 22:04 عصر
I'm really sorry for not having Persian keyboard layout once a month.

The problem with your code is actually too big to see.
you add all parameters to your sqlcommand for every row and that makes it 8 parameters per row which is well ... too many.
there are two workarounds
1.the fast way:
move the ExecuteNonQuery call inside the loop and clear the ParameterCollection after calling the procedure.
2.the right way:
Move the ExecuteNonQuery Inside the loop just like I said before and instead of adding parameters to your SqlCommand inside the loop Add them before the loop and just set the values inside.

And again, I'm sorry for writing this in English.I know It's hard for many people to read/understand.