与连接SQL SERVER 2000是一样的啊。<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %><html>
<script language="C#" runat="server">    protected void Page_Load(Object sender, EventArgs e) 
    {
        SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");
        SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);        DataSet ds = new DataSet();
        myCommand.Fill(ds, "Authors");        MyDataGrid.DataSource=ds.Tables["Authors"].DefaultView;
        MyDataGrid.DataBind();
    }</script><body>  <h3><font face="Verdana">Simple Select to a DataGrid Control</font></h3>  <ASP:DataGrid id="MyDataGrid" runat="server"
    Width="700"
    BackColor="#ccccff" 
    BorderColor="black"
    ShowFooter="false" 
    CellPadding=3 
    CellSpacing="0"
    Font-Name="Verdana"
    Font-Size="8pt"
    HeaderStyle-BackColor="#aaaadd"
    EnableViewState="false"
  /></body>
</html>最多就是OleDb的连接串有些不同。
连接串的建立: 你建一个扩展名为 .udl的文件,双击,根据提示进行设置。完成后用记事本打开,复制里面的字串替换
SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes") 里的东东。

解决方案 »

  1.   

    以下例子是将数据库表中的某一列绑定到列表控件:
    注意:Ole DB 用于访问SQL Server7.0及以后版本的数据库.
    protected OleDbConnection cn;
    protected OleDbCommand cm;
    protected OleDbDataAdapter da;
    protected DataSet ds;
    string Strconn="Provider=SQLOLEDB.1;User ID=sa;password=;Initial Catalog=Cardtest;Data Source=orant";private void Page_Load(object sender, System.EventArgs e)
    {
      if(!IspOstBack)
      {
       Bind();
       }
    }
    private void Bind()
    {
     cn=new OleDbConnection(Strconn);
     cn.Open();
     cm=new OleDbCommand();
     cm.Connection=cn;
     cm.CommandText="select type_id,kind_name from handset_type";
     ds=new DataSet();
     da=new OleDbDataAdapter(cm);
     da.Fill(ds);
     cn.Close();
     this.ddlCardName.DataSource=ds;
     this.ddlCardName.DataTextField="kind_name";
     this.ddlCardName.DataValueField="type_id";
     this.ddlCardName.DataBind();
    }