在asp.net前台页面中引入命名空间 和连接数据库

 

例如:<%@ Import Namespace="System.Data" %>

连接数据库

<%
string strconn = "Data Source=PC-201001081513;Initial Catalog=WebFirst;Integrated Security=True";
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cmd = new SqlCommand();
if (conn.State == ConnectionState.Closed)
{
conn.Open();


}

string ad = Request["name"]; //接收页面get方法的传值
string sql = "select Name,Valuses,ParentId from DaoHang where name='"+ad +"'";
cmd.CommandText = sql;
cmd.Connection = conn;
// System.Data.DataSet ds = new System.Data.DataSet();
// System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(cmd);
// sda.Fill(ds);
// if (ds.Tables[0].Rows.Count > 0)
//{

// }
SqlDataReader ar = cmd.ExecuteReader();
while (ar.Read())
{
Response.Write(ar.GetSqlString(0)+"</br>");
}


%>

原文地址:https://www.cnblogs.com/annabook/p/3562202.html