using System.Data;
using System.Data.SqlClient ;
private void Form1_Load(object sender, System.EventArgs e)
{
SqlConnection MunCnn = new SqlConnection ("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=test");
SqlDataAdapter MunDA = new SqlDataAdapter("SELECT * FROM mun",MunCnn);
MunCnn.Open() ;
DataSet MunDS=new DataSet();
MunDA.Fill(MunDS, "mun");
   
dataGrid1.CaptionText="sss";
dataGrid1.DataSource =MunDS.Tables["mun"];
MunCnn.Close() ;
}

解决方案 »

  1.   

    using System;
    using System.Data.SqlClient;public class TestADO
    {
        public static void Main()
        {
            SqlConnection conn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI; Initial Catalog=pubs");
            SqlCommand  cmd = new SqlCommand("SELECT * FROM employees", conn);
            try
            {        
                conn.Open();            SqlDataReader reader = cmd.ExecuteReader();            
                while (reader.Read())
                {
                    Console.WriteLine("First Name: {0}, Last Name: {1}", reader.GetString(0), reader.GetString(1));
                }
            
                reader.Close();
                conn.Close();
            }
            catch(Exception e)
            {
                Console.WriteLine("Exception Occured -->> {0}",e);
            }        
        }
    }
      

  2.   

    上面的方法也对,只不过很多的初者很难或者根本调试不会通过的了
    这样改正吧把
    SqlConnection conn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI; Initial Catalog=pubs");改为:SqlConnection conn =new SqlConnection("server=(local);database=mydb;uid=sa;pwd=cctv;");
    mydb是数据库名,sa是SQL用户名,cctv是用户sa的密码
      

  3.   

    http://www.aspxcn.com/dotnetarticle/login.aspx?id=26先注册一个用户进去再看看这篇文章吧