110,566
社区成员
发帖
与我相关
我的任务
分享
private static DataSet runMultiRowSelect(string sqlCommand, Hashtable parameters, string srcTable)
{
SqlDataAdapter oda;
DataSet ds;
SqlCommand myCmd;
using (SqlConnection conn = GetUnopenedConnection())
{
using (oda = new SqlDataAdapter(sqlCommand,conn))
try
{
conn.Open();
myCmd = new SqlCommand(sqlCommand, conn);
myCmd.CommandType = CommandType.StoredProcedure;
// Set up parameters
IDictionaryEnumerator htEnumerator = parameters.GetEnumerator();
while (htEnumerator.MoveNext())
{
if (log.IsDebugEnabled) log.Debug("About to add parameter with name of [" + htEnumerator.Key.ToString()
+ "] and value of [" + htEnumerator.Value + "].");
myCmd.Parameters.AddWithValueAdd(htEnumerator.Key.ToString(), htEnumerator.Value); /*这里可以看到Hashtable有值:Key值: @userID; Value值:100 */
}
if (log.IsInfoEnabled) log.Info("About to run store procedure of {" + sqlCommand + "}.");
{
ds = new DataSet();
oda.SelectCommand.CommandTimeout = Int32.Parse(Properties.Settings.Default.GlobalDatabaseTimeout);
oda.Fill(ds, srcTable);
}
if (log.IsDebugEnabled) log.Debug("Records successfully read.");
if (log.IsInfoEnabled) log.Info("Method exiting");
return (ds); /*程序在这里运行抛出异常:Procedure or function 'XXX' expects parameter '@userID', which was not supplied.*/
}
catch (Exception e)
{
string errorMsg = "Got exception of {" + e.Message + "} while trying to run SQL statement of [" + sqlCommand + "].";
if (log.IsWarnEnabled) log.Warn(errorMsg);
throw new clsUtil.MSSQLDatabaseException(errorMsg);
}
finally
{
conn.Dispose();
oda.Dispose();
}
}
}
myCmd.Parameters.AddWithValue(htEnumerator.Key.ToString(), htEnumerator.Value);
oda.Fill(ds, srcTable);