Code
public class Class_DB
{
private SqlConnection sqlconn;
private string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["ms38_ConnectionString"].ConnectionString;
public Class_DB()
{
sqlconn = new SqlConnection(strconn);
sqlconn.Open();
}
public DataSet article_list(string tablename,string classid,string listname)
{
SqlDataAdapter myda = new SqlDataAdapter("article_list", sqlconn);///article_list
myda.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter sp1 = new SqlParameter("@TableName", SqlDbType.VarChar, 50);
SqlParameter sp2 = new SqlParameter("@ClassID", SqlDbType.VarChar, 50);
SqlParameter sp3 = new SqlParameter("@ListName", SqlDbType.VarChar, 50);
sp1.Value = tablename;
sp2.Value = classid;
sp3.Value = listname;
myda.SelectCommand.Parameters.Add(sp1);
myda.SelectCommand.Parameters.Add(sp2);
myda.SelectCommand.Parameters.Add(sp3);
DataSet myds = new DataSet();
myda.Fill(myds, "ms_article");
return myds;
}
public void sql_close()
{
sqlconn.Close();
}
}
public class Class_DB
{
private SqlConnection sqlconn;
private string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["ms38_ConnectionString"].ConnectionString;
public Class_DB()
{
sqlconn = new SqlConnection(strconn);
sqlconn.Open();
}
public DataSet article_list(string tablename,string classid,string listname)
{
SqlDataAdapter myda = new SqlDataAdapter("article_list", sqlconn);///article_list
myda.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter sp1 = new SqlParameter("@TableName", SqlDbType.VarChar, 50);
SqlParameter sp2 = new SqlParameter("@ClassID", SqlDbType.VarChar, 50);
SqlParameter sp3 = new SqlParameter("@ListName", SqlDbType.VarChar, 50);
sp1.Value = tablename;
sp2.Value = classid;
sp3.Value = listname;
myda.SelectCommand.Parameters.Add(sp1);
myda.SelectCommand.Parameters.Add(sp2);
myda.SelectCommand.Parameters.Add(sp3);
DataSet myds = new DataSet();
myda.Fill(myds, "ms_article");
return myds;
}
public void sql_close()
{
sqlconn.Close();
}
}
Code
ALTER procedure [dbo].[article_list]
@TableName varchar(50), --表名
@ClassID varchar(50), --类名
@ListName varchar(50) --要获取的列明
as
exec('select '+@ListName+' from'+@TableName+' where ms_class='+@ClassID)
--select * from mrjzl
ALTER procedure [dbo].[article_list]
@TableName varchar(50), --表名
@ClassID varchar(50), --类名
@ListName varchar(50) --要获取的列明
as
exec('select '+@ListName+' from'+@TableName+' where ms_class='+@ClassID)
--select * from mrjzl