请解决此错误....查询值和目标字段的数量不相同. [英] Please solve this error....Number of query values and destination fields are not the same.

查看:54
本文介绍了请解决此错误....查询值和目标字段的数量不相同.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用access.i,可能会出错..
查询值和目标字段的数量不相同.
我的表格字段是...
自动隐瞒的ID

city_id,饭店名称,饭店评价,客人人数,持续时间,有效期,每人价格,位置,图像,包含,膳食计划,明智日程,排除,其他
字段是文本

我正在这样做

i am using access.i mam getting error..
Number of query values and destination fields are not the same.
my table fields are...
Id which is auto increament

city_id,Hotel_name,Hotel_Rating,No_of_guest,Duration,validity,price_per_person,Location,image,Inclusion,mealplan,Day_Wise_Itinerary,Exclusion,others
that fields are text

i am doing this

str = "~/image/" + uploadfile.FileName;
     uploadfile.SaveAs(Server.MapPath(str));
     con = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
     con.Open();
     cmd = new OleDbCommand("insert into nhvgjngh values('" + txtcity_id.Text + "','" + txthotel_name.Text + "','" + txthotal_rating.Text + "','" + txtguest.Text + "','" + txtduration_to.Text + "/" + txtduration_from.Text + "','" + txtvalidity_to.Text + "to" + txtvalidity_from.Text + "','" + txtprice_person.Text + "','" + txtlocation.Text + "','" + str + "','" + InclusionEditor.Text + "','" + MealplanEditor.Text + "','" + txtday_itinary.Text + "','" + txtexclusion.Text + "','" + txtother.Text + "')", con);
     cmd.ExecuteNonQuery();



请帮助我


thanx



please help me


thanx

推荐答案

使用此功能.由于ID是自动递增的,因此您不应在查询中传递它.
Use this. As ID is auto incremented, you should not pass it in query.
"insert into nhvgjngh (city_id,Hotel_name,Hotel_Rating,No_of_guest,Duration,validity,price_per_person,Location,image,Inclusion,mealplan,Day_Wise_Itinerary,Exclusion,others) values ('" + txtcity_id.Text + "','" + txthotel_name.Text + "','" + txthotal_rating.Text + "','" + txtguest.Text + "','" + txtduration_to.Text + "/" + txtduration_from.Text + "','" + txtvalidity_to.Text + "to" + txtvalidity_from.Text + "','" + txtprice_person.Text + "','" + txtlocation.Text + "','" + str + "','" + InclusionEditor.Text + "','" + MealplanEditor.Text + "','" + txtday_itinary.Text + "','" + txtexclusion.Text + "','" + txtother.Text + "')"


我在这里看到的第一个问题是Id是一个自动增量列.
在这种情况下,您不能插入ID.从查询中删除ID列值.
The first problem that I see here is that Id is an autoincrement column.
IN that case, you cannot insert into Id. Remove the id column value from your query.


尝试此操作

try this

str = "~/image/" + uploadfile.FileName;
uploadfile.SaveAs(Server.MapPath(str));
con = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
string strSql1="";
strsql1 = string.Format("insert into nhvgjngh(col1, col2,col3, col4,col5, col6,col7, col8,col9, col10,col11, col12,col13) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}')", txtcity_id.Text, txthotel_name.Text, txthotal_rating.Text, txtguest.Text, txtduration_to.Text / txtduration_from.Text, txtvalidity_to.Text + "to" + txtvalidity_from.Text, txtprice_person.Text, txtlocation.Text, str, InclusionEditor.Text, MealplanEditor.Text, txtday_itinary.Text, txtexclusion.Text, txtother.Text);
cmd = new OleDbCommand(strsql1, con);
cmd.ExecuteNonQuery();


替换
col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13
表nhvgjngh中的列名


replace
col1, col2,col3, col4,col5, col6,col7, col8,col9, col10,col11, col12,col13
with your column name from the table nhvgjngh


这篇关于请解决此错误....查询值和目标字段的数量不相同.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆