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

table如何 绑定数据库 (马上结贴)
@o@rt

------解决方案--------------------
读数据库: SqlConnection conn =null; SqlDataAdapter dapt = null; DataSet ds = new DataSet(); string strConnectionString = "Data Source=.;initial catalog=数据库;uid=sa;pwd=xxx "; string strSQL = "SELECT 字段 from 表 " try { conn = new SqlConnection(strConnectionString); conn.Open(); dapt = new SqlDataAdapter(strSQL,conn); dapt.Fill(ds, "table1 "); DataTable dt = ds.Tabls[0]; if(dt.Rows.Count > 0) { this.Text1.Text = dt.Rows[0][ "字段 "].ToString(); } } catch(System.Exception e) { this.Text1.Text = "错误 "+e.Message; } finally { if(conn!=null) conn.Dispose(); if(dapt!=null) dapt.Dispose(); }