C# 连接SqlServer数据库源码片段
在内容之余,把写内容过程中较好的一些内容段做个备份,下面的内容是关于C# 连接SqlServer数据库片段的内容,应该是对小伙伴也有用处。
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); 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); } }}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。