DLL version issue and SQL Parameters Issue

本文探讨了在使用参数化SQL查询时遇到的SqlException问题,并提供了具体的解决方案。通过调整DataTable中的空值处理方式,确保参数化查询能够正确执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 在工程中Reference dll: 

   1).specify version: true or false should be same.Other wise, there will be conflick between these dlls expecily that have depence.

   2). We can set all of them are true or all false.

2.SqlException: The parameterized query ## expects the pa... RSS

Resolved.

        
public void UpdateTableInfo(string command, string dbTableName, DataTable dataTable, IList<string> parameters) 
        { 
            _dataAdapter.InsertCommand 
= new SqlCommand(@command); 
            IList tableColumnTypes 
= GetTableColumnTypes(dbTableName); 
            
for (int i = 0; i < parameters.Count; i++
            { 
                _dataAdapter.InsertCommand.Parameters.Add(
new SqlParameter("@" + parameters[i], tableColumnTypes[i])); 
                _dataAdapter.InsertCommand.Parameters[
"@" + parameters[i]].SourceVersion = DataRowVersion.Current; 
                _dataAdapter.InsertCommand.Parameters[
"@" + parameters[i]].SourceColumn = dataTable.Columns[i].ColumnName; 
            } 
            SqlConnection conn 
= DbConnection; 
            _dataAdapter.InsertCommand.Connection 
= conn; 
            
using (conn) 
            { 
                _dataAdapter.Update(dataTable.DataSet, dbTableName); 
            } 
        }

 

I'm wondering if my problem possibly has to do with null or empty values in my DataTable ("dataTable"). The exception error seems to imply that a parameter value was not supplied in the parameterized query? Like the value of @Value0 was empty or null in my DataTable (for a particular row)?

If this is the case, how can I handle empty or null values in my DataTable so that this problem does not arise? Insert a DbNull value into my database for each empty or null value in the DataTable? How might that be best accomplished? I guess I would have to allow NULL values in my database table to do this?

 

转载于:https://www.cnblogs.com/Jessy/archive/2011/06/02/2068552.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值