繁体   English   中英

在 Visual Studio 2013 中检索数据 SQL 数据库并在网站上的 Gridview 中显示

[英]Retrieve data SQL database and display in Gridview on website in Visual Studio 2013

我创建了一个网站,它复制了谷歌之类的东西。 它只是一个搜索栏,让客户可以了解我们是否有他们需要的产品。

  1. 客户在网站上搜索产品。
  2. 查询发送到 SQL
  3. 结果以网格形式显示在网站上(可能是多个项目)

我目前正在使用 Visual Studios 来构建它。 但我不知道如何从我的数据库中获取数据来创建连接并带回一些结果。 我对此很陌生,如果有人问过这个问题,我深表歉意。

采取的步骤是在单击按钮时实现 SQL 连接,或者无论您的要求是什么Sql 指南

SqlConnection myConnection = new SqlConnection("user id=username;" + 
                                   "password=password;server=serverurl;" + 
                                   "Trusted_Connection=yes;" + 
                                   "database=database; " + 
                                   "connection timeout=30");

将 Gridview 添加到您的页面所需的位置,并将数据源设置为您的 datareader 教程的结果here

string strSQLconnection = "Data Source=dbServer;Initial Catalog=testDB;Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
SqlCommand sqlCommand = new SqlCommand("select * from table1", sqlConnection);
sqlConnection.Open();

SqlDataReader reader = sqlCommand.ExecuteReader();

GridView1.DataSource = reader;
GridView1.DataBind();

如果您想了解更多,请尝试更具体地回答您的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM