Calling a stored procedure with null parameters and SqlDataAdapter

喜欢而已 提交于 2019-12-12 04:37:15

问题


I have a stored procedure which I cann from my C# code. I am passing some parameters which I put in a HashTable first. It looks like that:

paramname1 value1
paramname2 value2
paramname3 value3

Any of the values can be null. So now I am going through that hash and add the params to the adapter:

foreach (DictionaryEntry entry in myHash)
{
    adapter.SelectCommand.Parameters.AddWithValue(entry.Key.ToString(), entry.Value);
}

This works, but when I try to fill a DataSet, it fails:

DataSet reportDataSet = new DataSet();
adapter.Fill(reportDataSet);

The error message is that it complains about a missing procedure parameter. Ideas?

Thanks :-)


回答1:


I think you have to check if its null and set it to DBNull.Value instead of null otherwise it thinks that the parameter is missing as it has a null value.



来源:https://stackoverflow.com/questions/3254203/calling-a-stored-procedure-with-null-parameters-and-sqldataadapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!