//建立ASP.NET Web 应用程序,直接在Page_load函数中加入一下代码,貌似就可以用了
public void Page_Load(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection("Data Source=.;uid=sa;pwd=sa;Database=NorthWind")) { string username = "forever"; string strSQL = "select * from table where name='" + username + "'"; SqlDataAdapter adapter = new SqlDataAdapter(strSQL, con); DataSet ds = new DataSet(); adapter.Fill(ds); foreach (DataRowView drv in ds.Tables[0].DefaultView) { Response.Write(drv["第一个字段"]+"|"+drv["第二个字段"]); } } }