日期:2014-05-16 浏览次数:20716 次
static void Main(string[] args)
{
string connString =‘连接字符串’;
SqlConnection conn = new SqlConnection(connString);
try
{
// Open the connection
conn.Open();
Console.WriteLine("Connection opened.");
//Do something
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = ‘SQL语句’;
SqlDataReader reader = comm.ExecuteReader(); //还有其他方法可用
while (reader.Read())
{
reader[str].ToString();
}
}
catch (SqlException e)
{
// Display the exception message
Console.WriteLine("SQL Error: " + e);
}
catch (Exception e)
{
// Display the exception message
Console.WriteLine("Error: " + e);
}
&nbs