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() ;
}
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() ;
}
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);
}
}
}
这样改正吧把
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的密码