更新时间:2023-01-12 20:57:24
确保发送正确的值和类型
Make sure you are sending in the proper values and types
da.InsertCommand.Parameters.Add("@name", SqlDbType.Money).Value =
textBox1.Text;
这是期望的浮动,但您正在发送文本.如果用户输入"ABC"会怎样?它不能转换为浮点数. DateTime列也是如此.
This is expecting a float but you are sending text. What happens if the user enters "ABC"? It can''t be converted to a float. The same goes for the DateTime column.
da.InsertCommand.Parameters.Add("@insurance_type", SqlDbType.NVarChar).Value =
comboBox2.SelectedItem ;
在这里,您需要一个字符串,但是SelectedItem是ListItem. ListItem将返回使用ToString方法将其转换为字符串,但这真的是您想要的吗?
Here you are expecting a string but SelectedItem is ListItem. The ListItem will return use the ToString method to convert it to a string, but is that really want you want?
我认为您必须在insert语句中指定列. >
I think you have to specify the columns in your insert statement.
Insert Into [Table Name] (Column1, Column2, Column3) Values (Val1, Val2, Val3)
您必须为表中的每一列提供一个值,并且必须按照正确的顺序来匹配表.
我的意思是;您必须在两边都匹配列数.如果有5列,则必须有5个参数.因此,括号中的列数必须与右侧的值数匹配.列1和值1的类型必须匹配,检查类型是否匹配.
好的lcuk
OI
You HAVE to provide a value for every column in the table and it has to be in the proper order to match the table.
What I mean by this is; you have to match the column count in both sides. If you have 5 columns, you have to have 5 parameters. So the column count in the paranthesis must match the value count in the right hand side. The types for the column 1 and value 1 has to match check if the types match.
Good lcuk
OI