表格字段和表格中的文本框不相同 [英] table fields and text boxes in form not same

查看:105
本文介绍了表格字段和表格中的文本框不相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在数据库中存储的文本框中输入值时.如果字段和文本框不相等,如何在数据库中插入值

我收到此错误

列名或提供的值数与表定义不匹配.

  USE  [Incometax]
 GO  

解决方案

使用以下内容更改INSERT语句:

  INSERT   INTO  other_source_income(Field1,Field2,... Field11) VALUES (Value1,Value2,... Value11) 


您需要指定所需值的字段如果您不向所有语句插入值,则在语句中插入.由于您没有提供这些字段,因此假设您要插入所有字段,因此会出现错误.如何做到这一点的一个例子是

  INSERT   INTO 表1(列1,第2列)' '  SqlParameter  [ 插入 插入表名(field1,field2,field3,.... .,fieldn)(value1,value2,value3,.....,valuen)



而不是使用
//不好的做法

 插入 插入表名(value1,value2,value3,.....,valuen)



最好使用插入查询过程.


when i am enter values in textboxes store in database. if not equal fields and textboxes how to insert values in database

i got this error

Column name or number of supplied values does not match table definition.

USE [Incometax]
GO

Change your INSERT statement with something like this:

INSERT INTO other_source_income (Field1, Field2,... Field11) VALUES (Value1, Value2,... Value11)


You need to specify the fields of the values you want to insert on your statement if you are not inserting values to all of them. Since you haven''t provided the fields, it assumes that you want to insert to all of them, hence the error. An example of how to do it would be

INSERT INTO Table1 (column1, column2) VALUES ('value1','value2')



Also, the way you''re constructing your query is dangerous, as its open to SQL injection attacks. Use
SqlParameter[^] instead of concatenating values to your query.


Make a good practice of passing the fields and values in insert query like

insert into tablename (field1,field2,field3,.....,fieldn) values(value1,value2,value3,.....,valuen)



instead of using
//bad practice

insert into tablename values(value1,value2,value3,.....,valuen)



better to use procedure for insert query.


这篇关于表格字段和表格中的文本框不相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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