日期:2014-05-18  浏览次数:20512 次

提一个asp.net的初级问题
我现在想把SQL查询出来的数据通过dataset的ds对象来获取,并把我需要的数据显示出来,在下面两句代码后面需要添加什么呢?才能使第三获取数据数据呢?请指教
sSql= "select   *   from   news   where   newsid= "+newsid;
DataSet   ds=new   DataSet();


txttitle.Value=ds.Tables[ "news "].Columns[ "newstitle "].ToString();


------解决方案--------------------
DataView dv = ds.Tables[0].DefaultView;
if(dv.Count != 0)
{
txttitle.Value = dv[0][ "newstitle "].ToString();
}
但是读取出来的数据可能不止一条呢

------解决方案--------------------
SqlConnection con = new SqlConnection( "连接字符串 ");
SqlCommand cmd = new SqlCommand( "sql语句 ",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
------解决方案--------------------
sSql= "select * from news where newsid= "+newsid;
DataSet ds=new DataSet();

SqlConnection conn = new SqlConnection(连接数据库字符串);
SqlDataAdapter da = new SqlDataAdapter(sSql,conn);
conn.open();
da.Fill(ds, "USERINFO ");
txttitle.Value=ds.Tables[ "news "].Rows[0][ "newstitle "].ToString();
都写
------解决方案--------------------
SqlConnection conn = new SqlConnection( "server=localhost;database=bgglxt;uid=sa;pwd= '7802456 ' ");
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT * FROM basic_plan ";
cmd.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
Repeater1.DataSource = ds.Tables[0].DefaultView;
Repeater1.DataBind();
da.Dispose();
------解决方案--------------------
搞复杂了,一个newsid应该对应一个txttitle吧

SqlConnection con = new SqlConnection( "连接字符串 ");
SqlCommand cmd = new SqlCommand( "sql语句 ",con);
txttitle.Value=cmd.ExecuteScalar().ToString();