请参考:
演练:Windows 窗体中的简单数据访问
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vbwlkwalkthroughdisplayingdatafromsingletableinwindowsform.htm

解决方案 »

  1.   

    在web下,我建议你把web的学会了 就可以保winform下的搞通的
    www.Microsoft.com/china/下很多东西,好好利用msdn的
    SqlConnection myConnection = new SqlConnection("server=mentorserver;database=Northwind;user id=mt");
    //创建SqlDataAdapter对象
    SqlDataAdapter myCommand = new SqlDataAdapter("select * from Categories", myConnection);

    //创建DataSet对象

    DataSet ds = new DataSet();

    //将查询结果填充到DataSet对象中

    myCommand.Fill(ds, "Categories");
     DataView CartView = ds.Table[0].DefaultViewMyDataGrid.DataSource = CartView; //指定数据源
    MyDataGrid.DataBind(); //显示
      

  2.   

    using System.Data;
    using System.Data.SqlClien;
    别忘了加命名空间
      

  3.   

    以Oracle的数据库为例,显示soctt下的表dept.
    现在窗体上画控件:oleDbConnection1、oleDbDataAdapter1、dataSet1、dataGrid1
    然后添加以下代码: oleDbConnection1.ConnectionString = "Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=dbflat;Extended Properties=\"\"";
    string strCom="select deptno, dname ,loc  from dept";
    oleDbConnection1.Open();
    oleDbDataAdapter1.SelectCommand=new OleDbCommand(strCom,oleDbConnection1);
    oleDbDataAdapter1.Fill(dataSet1,"dept");
    oleDbConnection1.Close();
    dataGrid1.DataSource=dataSet1;
             dataGrid1.DataMember="dept";然后dataGrid就显示数据了。
    如果是SQLServer的就把上述的oleDb换成sqlClient.