在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>");
}


%>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM