string strCon = "Integrated Security=SSPI;Initial Catalog='数据库名称';Data Source='本地计算机名';User ID='登录用户名';Password='登录用户密'";
SqlConnection con = new SqlConnection(strCon);
SqlCommand com = null;
SqlDataReader dr = null;
string SqlStr;
try
{
con.Open();
SqlStr = String.Format("select * from 表名");
com = new SqlCommand(SqlStr, con);
dr = com.ExecuteReader();
if(dr.Read())
{
string str = dr["字段名"].ToString();
}
dr.Close();
con.Close();
}
catch (System.Exception ex)
{
MessageBoxEx.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
[ 本帖最后由 红色警戒 于 2011-4-29 21:08 编辑 ]