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.

Have you tried a listview it can be data bound and can have multiple columns.

commented: Okay thanx alot i'll read on that. :D +0

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();
cn.open();
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);
da.fill(tbl);
cn.Close();
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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.