Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用SQLDataAdapter.Update时,如何知道将插入到数据源表中的列值_C#_Sqldataadapter - Fatal编程技术网

C# 使用SQLDataAdapter.Update时,如何知道将插入到数据源表中的列值

C# 使用SQLDataAdapter.Update时,如何知道将插入到数据源表中的列值,c#,sqldataadapter,C#,Sqldataadapter,在使用SqlDataAdapter.Update方法执行Insert之前,我需要检查将插入到数据源数据库表中的列的值 以下命令是否正确 scb.GetInsertCommand().Parameters[“@ProductName”].Value.ToString();--scb是SqlCommandBuilder 它总是抛出空异常: "unhandled exception of type 'System.NullReferenceException' occurred..." 这意味着@

在使用
SqlDataAdapter.Update
方法执行
Insert
之前,我需要检查将插入到数据源数据库表中的列的值

以下命令是否正确

scb.GetInsertCommand().Parameters[“@ProductName”].Value.ToString();--scb是SqlCommandBuilder
它总是抛出空异常:

"unhandled exception of type 'System.NullReferenceException' occurred..."
这意味着@ProductName参数具有空值

我没有给任何参数赋值。该列的值来自
datagridview
,该视图的源为
datatable


插入过程总是成功的,但我需要在插入之前检查插入的值。

当ToString()已经是字符串时,为什么要使用它?您只需要参数[“@ProductName”]。值如果删除,则会显示错误。请改为:(字符串)scb.GetInsertCommand()。参数[“@ProductName”]。值当ToString()已经是字符串时,为什么要使用它?您只需要参数[“@ProductName]”。值如果删除,则显示错误。强制转换为:(字符串)scb.GetInsertCommand()。参数[“@ProductName]”。值