C# ADO.NET怎样才能和SQL数据库连接

C# ADO.NET怎样才能和SQL数据库连接


烙印99
浏览 470回答 4
4回答

慕桂英546537

一个简单的例子: private DataTable sget(){SqlConnection conn = new SqlConnection(@"Data Source=.\sqlexpress;database=Asp600;user id=sa;password=123");//()里面是连接数据库的字符串,连接后用sqlconnection对象SqlDataAdapter ad=new SqlDataAdapter("select top 10 * from Count_Iplocal", conn);DataTable ds = new DataTable();ad.Fill(ds);return ds; }

慕雪6442864

private DataTable sget(){SqlConnection conn = new SqlConnection(@"连接数据库的字符串");conn.open();SqlDataAdapter ad=new SqlDataAdapter("你要查询的语名", conn);DataTable ds = new DataTable();ad.Fill(ds);return ds;}
打开App,查看更多内容
随时随地看视频慕课网APP