string Conn="server=.;database=Test;Integrated Security=SSPI";
SqlConnection con=new SqlConnection(Conn);
con.Open();
this.Label1.Text=con.State.ToString();
con.Close();
------------------------------------------------------------------------------------------------------
下面这段代码是返回特定的ID号的:)
string Conn="server=.;database=Test;Integrated Security=SSPI";
SqlConnection con=new SqlConnection(Conn);
con.Open();
SqlCommand cmd=new SqlCommand("select UserID from Test where UserName='yinxing'",con);
int d=(int)cmd.ExecuteScalar();
this.Label1.Text="yinxing 的ID号是:"+d.ToString();
con.Close();