日期:2014-05-19  浏览次数:21025 次

关于C# DataSet显示数据的问题,菜鸟请高手指点!
string       sql_connStr       =     "server=10.0.80.204;database=ERP;uid=ERP;pwd=erp ";
SqlConnection     sql_conn     =new     SqlConnection(sql_connStr);
sql_conn.Open();
SqlDataAdapter       da=new       SqlDataAdapter( "select   *   from     test     where         ID= ' "   +   strID   +   " ' ",sql_conn);  
string   Sqlstr= "select   from   test   where   ID= ' "   +   strID   +   " ' ";
SqlCommand   cmd=new   SqlCommand(Sqlstr,sql_conn);
cmd.CommandType=CommandType.Text;
// cmd.ExecuteNonQuery();
DataSet       ds=new       DataSet();    
   
da.SelectCommand=cmd;      
da.Fill(ds, "test ");
sql_conn.Close();
return   ds;


------解决方案--------------------
string sql_connStr = "server=10.0.80.204;database=ERP;uid=ERP;pwd=erp ";

SqlConnection sql_conn =new SqlConnection(sql_connStr);

SqlDataAdapter da=new SqlDataAdapter( "select * from test where ID= ' " + strID + " ' ",sql_conn);

DataSet ds=new DataSet();

da.Fill(ds, "test ");

if(ds.tables[0].Rows.Count !=0)
{
this.textBox1.Text = ds.tables[0].rows[0][ "ColName "].ToString();
}


如果绑定的话 则
this.textBox1.DataBingdings.Add( "Text ",ds.tables[0], "ColName ");//
此时将绑定至该ds的ColName的列