PL很好,有人在此更新按钮代码中遇到了问题(错误消息:无法将参数值从adatatable转换为int64) [英] PL nice someone i have aproblem in this update button code (erro message: faild to convert parameter value from adatatable to a int64)

查看:78
本文介绍了PL很好,有人在此更新按钮代码中遇到了问题(错误消息:无法将参数值从adatatable转换为int64)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int x;
con =新的SqlConnection(str);
da =新的SqlDataAdapter();
da.UpdateCommand =新的SqlCommand(更新客户SET名称= @名称,地址= @地址,insurance_cost = @ insurance_cost,record_date = @ record_date WHERE code_customer = @ code_customer",con);
da.UpdateCommand.Parameters.Add("@ name",SqlDbType.NVarChar).Value = textBox1.Text;
da.UpdateCommand.Parameters.Add("@ address",SqlDbType.NVarChar).Value = textBox2.Text;
da.UpdateCommand.Parameters.Add("@ insurance_cost",SqlDbType.Money).Value = textBox3.Text;
da.UpdateCommand.Parameters.Add("@ record_date",SqlDbType.DateTime).Value = dateTimePicker1.Value;
da.UpdateCommand.Parameters.Add("@ code_customer",SqlDbType.BigInt).Value = dset.Tables ["customers"];
con.Open();
x = da.UpdateCommand.ExecuteNonQuery();
con.Close();
如果(x> = 1)
MessageBox.Show(记录已更新");

int x;
con = new SqlConnection(str);
da = new SqlDataAdapter();
da.UpdateCommand = new SqlCommand("UPDATE customers SET name=@name,address=@address,insurance_cost=@insurance_cost,record_date=@record_date WHERE code_customer=@code_customer", con);
da.UpdateCommand.Parameters.Add("@name", SqlDbType.NVarChar).Value = textBox1.Text;
da.UpdateCommand.Parameters.Add("@address", SqlDbType.NVarChar).Value = textBox2.Text;
da.UpdateCommand.Parameters.Add("@insurance_cost", SqlDbType.Money).Value = textBox3.Text;
da.UpdateCommand.Parameters.Add("@record_date", SqlDbType.DateTime).Value = dateTimePicker1.Value;
da.UpdateCommand.Parameters.Add("@code_customer", SqlDbType.BigInt).Value = dset.Tables["customers"];
con.Open();
x = da.UpdateCommand.ExecuteNonQuery();
con.Close();
if (x >= 1)
MessageBox.Show("Record(s)has been updated");

推荐答案

如果您在此处看到错误:

If you''re seeing the error here:

da.UpdateCommand.Parameters.Add("@code_customer", SqlDbType.BigInt).Value = dset.Tables["customers"];



这是因为您试图将表转换为整数.您不能那样做.



It''s because you''re trying to cast a table to an integer. You can''t do that.


更改:
da.UpdateCommand.Parameters.Add("@code_customer", SqlDbType.BigInt).Value = dset.Tables["customers"];

收件人:

da.UpdateCommand.Parameters.Add("@code_customer", SqlDbType.BigInt).Value = dset.Tables["customers"].Rows[0][0];


那只是一个例子-您可能要使用正确的行/列参考编号/名称


That is just an example - you will probably want to use the correct row/column reference numbers/names


这篇关于PL很好,有人在此更新按钮代码中遇到了问题(错误消息:无法将参数值从adatatable转换为int64)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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