简体   繁体   English

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

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

I have created a website which replicates something like google.我创建了一个网站,它复制了谷歌之类的东西。 It is simply a search bar that allows customers to find out if we have the product they require.它只是一个搜索栏,让客户可以了解我们是否有他们需要的产品。

  1. The customer searches for product on website.客户在网站上搜索产品。
  2. Query is sent to SQL查询发送到 SQL
  3. Results is displayed on website in a grid (could be multiple items)结果以网格形式显示在网站上(可能是多个项目)

I am currently using Visual Studios to build this.我目前正在使用 Visual Studios 来构建它。 But I have no idea how to grab data from my database to create that connections and bring back some results.但我不知道如何从我的数据库中获取数据来创建连接并带回一些结果。 I'm new to this and I apologise if this has been asked.我对此很陌生,如果有人问过这个问题,我深表歉意。

The steps to take would be to implement a SQL connection when a button is clicked or whatever your requirement is Sql guide采取的步骤是在单击按钮时实现 SQL 连接,或者无论您的要求是什么Sql 指南

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

Add a Gridview to your page in required position, and set the datasource as the result from your datareader tutorial here将 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();

If you want to know more, try beeing more specific with your question如果您想了解更多,请尝试更具体地回答您的问题

暂无
暂无

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

相关问题 ASP.NET本地SQL Server数据库C#gridview数据绑定Visual Studio 2013 - ASP.NET local SQL Server database C# gridview data binding Visual Studio 2013 Visual Studio 2013 WebSite项目数据库。打开 - Visual Studio 2013 WebSite Project Database.Open 从 Visual Studio 2013 数据库项目中清理 SQL Server 数据库 - Clean SQL Server database from Visual Studio 2013 database project 在Visual Studio 2013中使用SqlCeResultSet进行SQL Server Compact Edition数据访问 - SQL Server Compact Edition Data Access with the SqlCeResultSet in Visual Studio 2013 从Visual Studio 2015运行在Visual Studio 2013的SQL Server数据工具中开发的SSIS包 - Running an SSIS package developed in SQL Server Data Tools for Visual Studio 2013 from Visual Studio 2015 如何使用发布配置文件将Visual Studio 2013中的项目和数据库导入网站 - How to import projects and database from visual studio 2013 to website using publish profile 如何从数据库(formview)中检索数据并将其相乘,Visual Studio - how to retrieve data from my database (formview) and multiply it, visual studio 将Excel数据导入到SQL Server数据库表并在gridview中显示 - import excel data to sql server database table and display in gridview Visual Studio 2013中的本地数据库连接错误 - Connection of local database error in Visual Studio 2013 连接到Visual Studio Express 2013 for Web中的数据库 - Connecting to database in Visual Studio Express 2013 for Web
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM