PDA

View Full Version : ارور کد ثبت



toorkaman
سه شنبه 06 مهر 1389, 13:55 عصر
سلام ، لطف می کنید ایراد این چند خط کد را به من بگید ،می خواهم اطلاعات داخل comboboxها وtextboxها دربانک ثبت شود،objadapter.InsertCommand = new SqlCommand();
objadapter.InsertCommand.Connection = objconn;
objadapter.InsertCommand.CommandText = "insert into daneshjo(univer,reshte,maghtah,nezam,nimsal,men,wo man,...) values(@field1,@field2,@field3,@field4,@field5,@fi eld6,@field7...)";
objadapter.InsertCommand.Parameters.AddWithValue("@field1", comboBox6.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field2", comboBox1.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field3", comboBox5.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field4", comboBox4.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field5", comboBox7.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field6", textBox1.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field7", textBox1.Text.Trim());
objconn.Open();
objadapter.InsertCommand.ExecuteNonQuery();این خط را ارورsyntaxمیگیره
objconn.Close();

ایمان مدائنی
سه شنبه 06 مهر 1389, 14:30 عصر
مشكل از كوئري هست !
values(@field1,@field2,@field3,@field4,@field5,@fi eld6,@field7...)";

اون رنگ قرمز يك فاصله اضافه داره

ایمان مدائنی
سه شنبه 06 مهر 1389, 14:31 عصر
ارور syntax مروط به كوئري ميباشد

محسن شامحمدی
سه شنبه 06 مهر 1389, 17:23 عصر
ترکمن جان
پارامترها نباید فاصله داشته باشند
وگرنه مشکل گرامری پیش میاد

mmd2009
چهارشنبه 07 مهر 1389, 03:48 صبح
با سلام

این کد رو اینطوری بنویس :



objadapter.InsertCommand = new SqlCommand();
objadapter.InsertCommand.Connection = objconn;
objadapter.InsertCommand.CommandText = "insert into daneshjo(univer,reshte,maghtah,nezam,nimsal,men,wo man) values+"
"(@field1,@field2,@field3,@field4,@field5,@field6,@ field7)";
objadapter.InsertCommand.Parameters.AddWithValue("@field1", comboBox6.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field2", comboBox1.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field3", comboBox5.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field4", comboBox4.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field5", comboBox7.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field6", textBox1.Text.Trim());
objadapter.InsertCommand.Parameters.AddWithValue("@field7", textBox1.Text.Trim());
objconn.Open();
objadapter.InsertCommand.ExecuteNonQuery();
objconn.Close();


کد خودت رو میذاشتی بهتر بود و اگر این کدت بوده که اروش رو دوستان هم گفتن. اگر باز مشکلی بود بگید.

پ ن :

کدت رو تو تگ های مربوط مثل php یا ... بذار که خوندنش راحت باشه