急谁知道用.net(c#)怎么从表里查数据了,比如我要查一条数据在另个页面显示这条数据的详细信息
2个回答
展开全部
index.aspx?id=0,这是页面传值的方式,前面是页面名称,后面是你要那条数据的查询条件
然后就是写个方法
public static DataSet SelOne(int id)
{
string sql = string.Format("SELECT * FROM dbo.telsafeType WHERE typeId={0}",id);
return Query(sql);
}
public static DataSet Query(string SQLString, params SqlParameter[] cmdParms)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
try
{
da.Fill(ds, "ds");
cmd.Parameters.Clear();
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
}
然后就是写个方法
public static DataSet SelOne(int id)
{
string sql = string.Format("SELECT * FROM dbo.telsafeType WHERE typeId={0}",id);
return Query(sql);
}
public static DataSet Query(string SQLString, params SqlParameter[] cmdParms)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
try
{
da.Fill(ds, "ds");
cmd.Parameters.Clear();
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询