在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