|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
subset of the fields stored in a datasetwant to do - I have a dataset that consists of all the rows and columns of a table (say emp). I also have a datagrid control on my windows form. I would like to extract all the row values for a particular field (say empname) from the dataset, i.e without connecting to the database and display it in my datagrid. Can someone tell me how to do this - here is the code - OleDbDataConnection cn = new OleDbDataConnection(connectionstring); OleDbDataAdapter da = new OleDbDataAdapter("select * from emp" , cn); DataSet ds = new DataSet(); da.Fill(ds, "e"); >From ds, I would like all the row values of the column/field empname in either a seperate table, or view, or an array - something that I candirectly use as a datasource for my datagrid. Thanks, Lb Labrynth,
Be aware that the dataset is a wrapper around datatables and datarelations. Therefore you show the rows of a datatable in your grid. There are more posibilities in your case it can be just. DataGrid1.DataSource = ds.Tables(0); (I would never name your table "e". That is one of the worst names for a variable in Net. It is the standard for the result of an event. "emp" is better in this case. I hope this helps, Cor Show quote "labrynth" <labrynth.thoug***@gmail.com> schreef in bericht news:1142705168.001230.311620@i40g2000cwc.googlegroups.com... >I have recently started coding in .net technologies. Here is what I > want to do - > > I have a dataset that consists of all the rows and columns of a table > (say emp). > > I also have a datagrid control on my windows form. > > I would like to extract all the row values for a particular field (say > empname) from the dataset, i.e without connecting to the database and > display it in my datagrid. > > Can someone tell me how to do this - > > here is the code - > > OleDbDataConnection cn = new OleDbDataConnection(connectionstring); > OleDbDataAdapter da = new OleDbDataAdapter("select * from emp" , cn); > > DataSet ds = new DataSet(); > > da.Fill(ds, "e"); > >>From ds, I would like all the row values of the column/field empname in > either a seperate table, or view, or an array - something that I can > directly use as a datasource for my datagrid. > > Thanks, > Lb > Thank you Cor, for the reply.
My question was, how do I display all the rows pertaining to a single "column/field" of a dataset (which as you said is a wrapper over multiple tables and relations in a database). DataGrid1.DataSource = ds.Tables[0] would get me all the rows pertaining to all the columns (as opposed to just the one column empname) from the dataset table 'emp'. I need all the row values pertaining to just one column from the dataset table 'emp' displayed in the datagrid. Basically I have a form , that lets you select a table, and then displays all the fields of that table in a list box, and upon selection of fields from teh list box, displays all the row values for the fields selected, in a data grid. Labrynth
> ds.Tables[0].DefaultView.Rowfilter = "Emp = 'Whatever'"; // for a string> My question was, how do I display all the rows pertaining to a single > "column/field" of a dataset (which as you said is a wrapper over > multiple tables and relations in a database). > > DataGrid1.DataSource = ds.Tables[0] DataGrid1.DataSource = ds.Tables[0].DefaultView; I hope this helps, Cor |
|||||||||||||||||||||||