PDA

View Full Version : اشکال در insert into



behzadk
سه شنبه 22 آبان 1386, 08:28 صبح
با سلام
اشکال این کد چیه ؟

string command,field;
field = "code,transact,type,area,address,spc,u_spc,price,ej are,rahn,credi,pish,bis,home,agri,t_type,working,c on_work,f_count,count_v,floors,water,w_count,elect ,gas,e_count,g_count,phonep_count,bedcount";
SqlConnection cnn = new SqlConnection("data source=(local);database=houses;uid=sa;password=1;");
SqlCommand cmd = new SqlCommand();
command = "insert into houses (" + field + ") valuses('20'," + (comboBox1.SelectedIndex) + "," + (comboBox2.SelectedIndex) + "," + (Convert.ToInt32(textBox24.Text)) + "," + "'" + textBox1.Text + "'" + "," + (Convert.ToInt32(textBox6.Text)) + "," + (Convert.ToInt32(textBox7.Text)) + "," + (Convert.ToDouble(textBox2.Text)) + "," + (Convert.ToDouble(textBox4.Text)) + "," + (Convert.ToDouble(textBox3.Text)) + "," + (Convert.ToDouble(textBox5.Text)) + "," + (check(checkBox1)) + "," + (check(checkBox2)) + "," + (check(checkBox3)) + "," + (check(checkBox4)) + "," + "'" + textBox8.Text + "'" + "," + (check(checkBox5)) + "," + "'" + textBox9.Text + "'" + "," + (Convert.ToInt32(textBox10.Text)) + "," + (Convert.ToInt32(textBox11.Text)) + "," + (Convert.ToInt32(textBox12.Text)) + "," + (check(checkBox7)) + "," + (Convert.ToInt16(textBox13.Text)) + "," + (check(checkBox8)) + "," + (Convert.ToInt16(textBox14.Text)) + "," + (check(checkBox9)) + "," + (Convert.ToInt16(textBox15.Text)) + "," + (check(checkBox10)) + "," + (Convert.ToInt16(textBox16.Text)) + "," + (Convert.ToInt16(textBox18.Text)) + ")";
cmd.CommandText = command;
cmd.Connection = cnn;
cnn.Open();
if (cmd.ExecuteNonQuery() == 0)
MessageBox.Show("عمل ثبت با موفقیت انجام شد");
else
MessageBox.Show("عمل ثبت با شکست مواجه شد");
cnn.Close();

eshaghi
سه شنبه 22 آبان 1386, 13:00 عصر
سلام
یک نمونه کد برایت می گذارم درست جواب می دهد

SqlConnection cnn = new SqlConnection("server=;database=ajans;Integrated Security=True;");
string str1;
str1 = "insert into land (metter,address,fee,allprice,lim,doc,detail,transa ct,idclient,utility,del,type) values ('" +
metter.Text + "','" + address.Text + "','" + fee.Text + "', '"+ allprice.Text +"' , '"+ lim.Text +"' , '"+ doc.Text +"' , '" +
detail2.Text + "' ,'f','" + temp2.Text + "' , '" + utility.Text + "','f','client')";

SqlCommand sqlcom2 =new SqlCommand();
cnn.Open();
sqlcom2.Connection=cnn;
sqlcom2.CommandText=str1;
sqlcom2.ExecuteNonQuery();
cnn.Close();

behzadk
سه شنبه 22 آبان 1386, 15:59 عصر
با تشکر از راهمایی شما
حل شد