[英]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.
它只是一个搜索栏,让客户可以了解我们是否有他们需要的产品。
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.