Hello Guys

I am trying create a DataGrid in Windows forms application, but i am unable to fill the data into that.

I am using data sets and data adapters for that, but i am getting a empty datagrid.

I am quite new to c# so can some body please help me.(.in using Data reader , and Data sets to fill the values in Datagrid ) please.

Thanks

string Conn;

            Conn = "Dsn=Filter;uid=DBA;pwd=sql";            OdbcConnection Connection = new OdbcConnection(Conn);
            Connection.Open();
             OdbcCommand Cmd = new OdbcCommand("select * from Employees",Connection);
             OdbcDataAdapter Da = new OdbcDataAdapter(Cmd);
            DataSet Ds = new DataSet("Employees");
            Da.Fill(Ds);
            GridView1.DataSource = Ds.Tables;

try adding GridView1.Databind() at the end.

also, try changing line 9 from

GridView1.DataSource = Ds.Tables;

to

GridView1.DataSource = Ds;

alternatively, if there is more than one table in the Dataset, then specify a table like so:

GridView1.DataSource = Ds.Tables[0];

also, insert a breakpoint and check that the dataset contains values...its a mistake ive made in the past ;)

Hello Ryshad

Thanks for your reply..Its working now..

I also want to know, is there any way we can use windows forms application in Web application or website ..

Like by importing or by adding reference..[any how]

Thanks

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.