怎么将.net连接到数据库

时间:2012-10-02 04:32:22
【文件属性】:

文件名称:怎么将.net连接到数据库

文件大小:20KB

文件格式:DOC

更新时间:2012-10-02 04:32:22

三层开发

SqlConnection con = new SqlConnection("DataSource=localhost;Integrated Security=SSPI;Initial Catalog=northwind"); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "SELECT CategoryID, CategoryName FROM Categories"; con.Open(); SqlDataReader read = catCMD.ExecuteReader(); while(read.Read()) { Console.WriteLine("\t{0}\t{1}",read.GetInt32(0),read.GetString(1)); } read.Close(); con.Close(); }


网友评论