Hi I am really new to c#(I used to do vb.net) and I need some help with a problem. I am wondering what the equivalent of a datalist or detailsview in asp.net is in a c# winforms application and how to use it. I have data in a database and I want to retrieve it and display it in a form view when the user clicks a button to search for a record based on a control value as a parameter for the select query. I do not want to use the grid view and anyway Visual Studio 2012 seems waayyy different than 2010.

I use : Visual Studio pro 2012 with C#
Ms sql express 2012

This is for a winforms application.
Please I would really appreciate some help on this.

5 Years
Discussion Span
Last Post by tinstaafl

Hello !
If you are using windows form application and want to show the records from database to your from you can do like this .First add a textbox name txtSearch and then a button name btnSearch and a gridview name dgvSearch . now use this code.

sqlConnection cn = new sqlconnection("connection string");
datatable tbl = new datatable();
string strQuery = "";
strQuery = @"Select * from table1 where 1=1 ";

if(txtSearch.text != "")
strQuery = strQuery + " and field1 = " + txtSearch.text;
//---as above you can also use othere controls like datetime picker , combo box etc 
//to filter your records. just add conditions as mentioned above.
sqldataadapter da = new sqldataadapter(strQuery,cn);
dgvSeach.datasource = tbl;

As i typed it here and this editor is not case sensitive so may be you have to change little bit.

Best Regards

Edited by M.Waqas Aslam


The best control to use when reading records from a database is probably a DataGridView as it's just a table which you can configure to display as much or as little as you like. The only difficult aspect of a DGV is getting your head around accessing individual cells, but if you've used arrays in vb you'll find it a breeze!


I do not want to use the grid view

A listview is probably the next best choice. I believe it has pretty much the same capabilities, except that everything needs to be done separately. It has a Details view and the Gridlines are optional.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.