在內容之餘,把寫內容過程中較好的一些內容段做個備份,下面的內容是關於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);
}
}
}