PDA

View Full Version : سوال: من و پروژه و SQLServer



bargesabz
سه شنبه 31 شهریور 1388, 18:33 عصر
با سلام به همه دوستان
هنگام درج یک رکورد با دستور زیر



case 1:

noehedye = '2';





SqlCommand hcom = new SqlCommand("INSERT INTO Hedye( nkhayyer,noehedye,fkhayyer,dtahvil,babate,daryafko nande,numresid,elamevosol,shfanbar,codkala,namekal a,vahedkala,mvarede,bvahed,mablaqhkol)"

+ "VALUES('" + textBox2.Text + "','" + noehedye + "','" + textBox3.Text + "','" + textBox1.Text + "','" + textBox12.Text + "','" + textBox13.Text + "','" + textBox11.Text + "','" + comboBox4.Text + "','" + textBox8.Text + "','" + textBox6.Text + "','" + textBox4.Text + "''" + comboBox3.Text + "','" + textBox5.Text + "','" + textBox7.Text + "','" + textBox14.Text + "')", hemophili);

hemophili.Open();

hcom.ExecuteNonQuery();

MessageBox.Show("رکورد ذخیره شد");


error زیر رو در خط
hcom.ExecuteNonQuery(); می ده



There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
فکر می کنم که این خطا می گه که تعداد عناصر در بند insert باید با تعداد عناصر در بندvalues برابر باشه
و تعدادشون برابره پس مشکل از کجاست؟

DataMaster
سه شنبه 31 شهریور 1388, 19:36 عصر
اينجا كه بخش #C نيست
مشخصا اگه برنامه رو ديباگ كني و دستوري رو كه داره اجرا ميشه چك كني ميفهمي كه مشكل توي دستور هست

textBox4.Text + "''" + comboBox3.Text +
مشكل داره ديگه

bargesabz
شنبه 04 مهر 1388, 22:25 عصر
با سلام دوباره به همه دوستان


errorزیر به چه دلیلی می یاد ؟



String or binary data would be truncated.
The statement has been terminated

محمد سلیم آبادی
دوشنبه 06 مهر 1388, 00:29 صبح
با سلام دوباره به همه دوستان


errorزیر به چه دلیلی می یاد ؟



String or binary data would be truncated.
The statement has been terminated

به احتمال زیاد به این دلیل است که طول مقداری را که سعی می کنین درج کنید از طول تعریف شده برای ستون مورد نظر بیشتر است.