protected void Page_Load(object sender, EventArgs e)
{
//链接数据库
//string connStr = ConfigurationManager.AppSettings["connString"];
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=服务器名;Initial Catalog=数据库名;User Id=sa;Password=;";
conn.Open();
try
{
lblSQLServer.Text = "成功打开SQLServer数据库!";
string sql = "select Name from Enum_Car_PlateType order by ID";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
string ss = dt.Rows[i]["Name"].ToString();
ddlPlateType.Items.Add(ss);
}
}
catch (SqlException ex)
{
lblSQLServer.Text = "打开SQLServer数据库失败!";
ex.Errors.ToString();
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}
}