DBHelper类中怎样调用存储过程?????????? 各给高手们,请问DBHelper类中怎样调用存储过程???DBHelper类中的方法应该怎样写 才能把存储过程 参数传进去的,最好能有详细代码。谢谢各位了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.cnblogs.com/08shiyan/archive/2010/07/17/1779391.html public static class DatabaseContext { public static DbCommand GetStoredProcCommand(DbInstance database, string storedProcName) { //Trace.WriteLine(storedProcName, "调用命令:"); return database.GetStoredProcCommand(storedProcName); } public static DbCommand GetSqlStringCommand(DbInstance database, string sqlString) { //Trace.WriteLine(storedProcName, "调用命令:"); return database.GetSqlStringCommand(sqlString); } public static IDataReader GetDataRecord(DbInstance database, DbCommand dbCommand) { //Trace.WriteLine(string.Format("{0:HH:mm:ss:ms}", DateTime.Now), "开始执行时间:"); var dr = database.ExecuteReader(dbCommand); //Trace.WriteLine(string.Format("{0:HH:mm:ss:ms}", DateTime.Now), "结束执行时间:"); return dr; } }//调用var dc = DatabaseContext.GetStoredProcCommand(database,"up_TMS_Task_RetrieveByOrderId"); database.AddInParameter(dc, "@orderId", DbType.Int32, orderId); database.AddInParameter(dc, "@userId", DbType.Guid, userId); http://bowfly.blog.163.com/blog/static/826034020086723543581/ 调用存储过程与执行普通的SQL语句的方式没多大分别,将sql语句改为存储过程的名字,CommandType的属性设置为存储过程的格式而不是文本的格式,传参是一样的使用XXXParameter。 string connstr = "数据库连接字符串"; SqlConnection conn = new SqlConnection(connstr); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "select * from tbl_user where username=@username"; cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 50)); cmd.Parameters["@username"].Value = "kingdom_0"; cmd.ExecuteNonQuery(); conn.Close(); 加上一句。。 cmd.Connection = conn; WIN7关机确认程序 函数的声明 file.delete 文件,提示文件由另一进程正在使用 使用c#的GZipStream时总是报错:GZip 头中的幻数不正确 wpf实现窗体一次完全显示 哪里能下到C#开发程序的源代码? 在C#中,在Windows Media Player 10 SDK中,如何使Windows Media Player播放流? VS2008 .NetFramework3.5 DataGridView 同步数据到绑定的数据源和数据库 文本的显示? 请问谁有 校验位X采用UPU通用的"mod11"计算方式 的C#代码实现? text拉动问题求助 C# GIF动画各帧透明的处理
public static class DatabaseContext
{
public static DbCommand GetStoredProcCommand(DbInstance database, string storedProcName)
{
//Trace.WriteLine(storedProcName, "调用命令:");
return database.GetStoredProcCommand(storedProcName);
} public static DbCommand GetSqlStringCommand(DbInstance database, string sqlString)
{
//Trace.WriteLine(storedProcName, "调用命令:");
return database.GetSqlStringCommand(sqlString);
} public static IDataReader GetDataRecord(DbInstance database, DbCommand dbCommand)
{
//Trace.WriteLine(string.Format("{0:HH:mm:ss:ms}", DateTime.Now), "开始执行时间:"); var dr = database.ExecuteReader(dbCommand); //Trace.WriteLine(string.Format("{0:HH:mm:ss:ms}", DateTime.Now), "结束执行时间:"); return dr;
}
}//调用var dc = DatabaseContext.GetStoredProcCommand(database,"up_TMS_Task_RetrieveByOrderId");
database.AddInParameter(dc, "@orderId", DbType.Int32, orderId);
database.AddInParameter(dc, "@userId", DbType.Guid, userId);
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "select * from tbl_user where username=@username";
cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 50));
cmd.Parameters["@username"].Value = "kingdom_0";
cmd.ExecuteNonQuery();
conn.Close();
cmd.Connection = conn;