SqlConnection connection = Connect();
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = sprocName;
command.Connection = connection;
//loop through the dictionary
foreach (string key in paramList.Keys)
{
command.Parameters.AddWithValue(key, paramList[key]);
}
SqlDataReader dataReader = command.ExecuteReader();
我正在尝试从数据库读取数据,当我传递相同的参数并执行SP时,我会得到正确的结果。但是在SqlDataReader dataReader = command.ExecuteReader();
处,当我检查(dataReader.HasRows
)时,它返回false!
答案 0 :(得分:0)
您的密钥是否包含'@',例如,如果密钥参数名称 EmployeeId 然后需要添加以下参数
commnad.Parameters.AddWithValue('@EmployeeId', 1);
答案 1 :(得分:0)
执行up_GetAtt @ pageNumber = 1,@ pagesize = 10,@ PID = 1000,@ DeID = NULL, @DeName = NULL,@ SortByColumn ='ReleaseDate',@ SortOrder ='DESC'这是 我要传递的参数
您需要将C#空值转换为DBNull
SqlConnection connection = Connect();
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = sprocName;
command.Connection = connection;
//loop through the dictionary
foreach (string key in paramList.Keys)
{
command.Parameters.AddWithValue(key, paramList[key] == NULL? DBNull.Value : paramList[key]);
}
SqlDataReader dataReader = command.ExecuteReader();
鉴于缺少信息可以帮助您更好,请检查常见错误