简体   繁体   中英

Retrieving data from database in Visual C#

Background

I am writing my first c# application, and would like to display the results of an SQL query in my application.

I would like the query to run against the database on a button click event. The results are to be displayed as read only and I would like them to be displayed in a table, not text boxes.

Form

What I have managed to create so far by drag and dropping from the 'ToolBar' in Visual Studio 2014.

桂

SQL query

 select * from station 

This isn't my exact query but it doesn't differ much as is still a select statement.

What I have done so far

  • Connected a dataset which includes the table I want to run the query on.
  • Added datagridview
  • Added button

Question

Could some one point me in the right direction? I don't necessarily want someone to write the code just advise what the next step is.

What do I do next?

My guess

I create some kind of event on button click that runs the query and brings back the records in the datagridview?

I have no idea how to do the above is it is correct however.

If you double click "button1" in visual studio it should create the event for you and take you to the code. Then you need to write the code that will execute when the button is clicked. Take a look at this question: Populate a datagridview with sql query results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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