5154

Good Luck To You!

asp.net 简单查询实例,如何实现基础数据查询功能?

``csharp,protected void Page_Load(object sender, EventArgs e),{, string connectionString = "Data Source=server;Initial Catalog=database;User Id=user;Password=password";, using (SqlConnection con = new SqlConnection(connectionString)), {, string query = "SELECT * FROM Users WHERE UserName='John'";, SqlCommand cmd = new SqlCommand(query, con);, con.Open();, SqlDataReader reader = cmd.ExecuteReader();, while (reader.Read()), {, Response.Write("User ID: " + reader["UserID"].ToString() + "");, }, reader.Close();, },},``,这段代码连接到一个名为“database”的数据库,从“Users”表中查询用户名为“John”的用户信息,并将用户ID输出到网页上。
<< 1 >>
«    2025年8月    »
123
45678910
11121314151617
18192021222324
25262728293031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
    文章归档
    网站收藏
    友情链接

    Powered By Z-BlogPHP 1.7.3

    Copyright Your WebSite.Some Rights Reserved.