当前位置: 代码迷 >> ASP.NET >> table怎么 绑定数据库 (马上结贴)
  详细解决方案

table怎么 绑定数据库 (马上结贴)

热度:9509   发布时间:2013-02-26 00:00:00.0
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(); }
  相关解决方案