asp.net(c#)中如何使用存储过程?请大家帮忙
1个回答
展开全部
public DataSet getDataByPage(int pageIndex)
{
DataSet ds = new DataSet();
String m_connectionString = ConfigurationSettings.AppSettings["connectionString"].Trim();
OleDbConnection conn = null;
String tablename = " mytable"; //表名
String orderName = "orderTime"; //排序的字段名
try
{
conn = new OleDbConnection(m_connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "pagination";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.Add(new OleDbParameter("@tablename",OleDbType.VarChar));
cmd.Parameters["@tablename"].Value = tablename;
cmd.Parameters.Add(new OleDbParameter("@tableField",OleDbType.VarChar));
cmd.Parameters["@tableField"].Value = " * " ;
cmd.Parameters.Add(new OleDbParameter("@orderName",OleDbType.VarChar));
cmd.Parameters["@orderName"].Value = orderName;
cmd.Parameters.Add(new OleDbParameter("@pageSize",OleDbType.Integer));
cmd.Parameters["@pageSize"].Value = m_pageSize;
cmd.Parameters.Add(new OleDbParameter("@pageIndex",OleDbType.Integer));
cmd.Parameters["@pageIndex"].Value = pageIndex;
cmd.Parameters.Add(new OleDbParameter("@doCount",OleDbType.Integer));
cmd.Parameters["@doCount"].Value = 0;
cmd.Parameters.Add(new OleDbParameter("@orderType",OleDbType.Integer));
cmd.Parameters["@orderType"].Value = 1;
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(ds,"music");
}
catch(Exception e)
{
System.Diagnostics.Trace.WriteLine(e.Message);
}
finally
{
conn.Close();
}
return ds;
}
//绑定数据到DateGrid
private void BindData(int pageIndex)
{
DataView dataview = new DataView(this.getDataByPage(pageIndex).Tables["newdata"]);
DataGrid1.DataSource = dataview;
DataGrid1.DataBind();
}
应该没有问题!
{
DataSet ds = new DataSet();
String m_connectionString = ConfigurationSettings.AppSettings["connectionString"].Trim();
OleDbConnection conn = null;
String tablename = " mytable"; //表名
String orderName = "orderTime"; //排序的字段名
try
{
conn = new OleDbConnection(m_connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "pagination";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.Add(new OleDbParameter("@tablename",OleDbType.VarChar));
cmd.Parameters["@tablename"].Value = tablename;
cmd.Parameters.Add(new OleDbParameter("@tableField",OleDbType.VarChar));
cmd.Parameters["@tableField"].Value = " * " ;
cmd.Parameters.Add(new OleDbParameter("@orderName",OleDbType.VarChar));
cmd.Parameters["@orderName"].Value = orderName;
cmd.Parameters.Add(new OleDbParameter("@pageSize",OleDbType.Integer));
cmd.Parameters["@pageSize"].Value = m_pageSize;
cmd.Parameters.Add(new OleDbParameter("@pageIndex",OleDbType.Integer));
cmd.Parameters["@pageIndex"].Value = pageIndex;
cmd.Parameters.Add(new OleDbParameter("@doCount",OleDbType.Integer));
cmd.Parameters["@doCount"].Value = 0;
cmd.Parameters.Add(new OleDbParameter("@orderType",OleDbType.Integer));
cmd.Parameters["@orderType"].Value = 1;
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(ds,"music");
}
catch(Exception e)
{
System.Diagnostics.Trace.WriteLine(e.Message);
}
finally
{
conn.Close();
}
return ds;
}
//绑定数据到DateGrid
private void BindData(int pageIndex)
{
DataView dataview = new DataView(this.getDataByPage(pageIndex).Tables["newdata"]);
DataGrid1.DataSource = dataview;
DataGrid1.DataBind();
}
应该没有问题!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询