public void Connection()
{
string connstr="server=10.64.2.80;user id=ieb;pwd=ieb;database=cust";
string sql="select * from elogin1";
//創建SqlConnection和SqlCommand對象
SqlConnection conn=new SqlConnection(connstr);
SqlCommand com=new SqlCommand(sql,conn);
try
{
//打開數據庫連接和執行SQL語句
conn.Open();
com.ExecuteNonQuery();
this.Label1.Text="未出現異常";
}
catch(SqlException ex)
{
this.Label1.Text="<b>數據庫執行錯誤</b><br>";
this.Label1.Text+="錯誤信息:"+ex.Source+"<br>";
this.Label1.Text+="錯誤行號:"+ex.LineNumber+"行<br>";
this.Label1.Text+="詳細信息:"+ex.Message+"<br>";
}
finally
{
conn.Close();
}
}