Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot get rid of parent in grid

Status
Not open for further replies.

litton1

Technical User
Apr 21, 2005
584
GB
Hi all, I have been teaching myself DT, DS, and grids etc, but I am trying to return a result from a DAL and then using the data source to fill the grid. All has gone well except that in my grid I have to click on an annoying hairline cross to display my data, something to do with parent data? Please can someone advise me on the best practice that will avoid this dilemma? The code i am using is:
DAL
Code:
public OdbcDataAdapter CatDataAdap()
{
     string sql = "SELECT category_id, category,    
     category_description, in_report FROM elitesalon.category";
     daCat = new OdbcDataAdapter(sql,conn);
     return daCat;
}

in the main form
Code:
OdbcDataAdapter da;
da= dc.CatDataAdap();
this.dsCat = new DataSet("Categrory");
da.Fill(dsCat);
dgcategory.DataSource = this.dsCat;

thx T

Age is a consequence of experience
 
Solved! I was using the DS and should have used the DT, i changed the last line in the main form to:
Code:
dgcategory.DataSource = this.dsCat.Tables[0].DefaultView;

Age is a consequence of experience
 
be aware that most "Real Coders" would never use the Data Adapter that MS provides as it is too heavy for most usage. As a matter of fact, when hiring people if they use Data adapters I eliminate them from my list.

just thought you might want to know

bassguy


 
Right, that is actually interesting as I would have thought that it would be the other way round? To be honest I have not used one data adapter in the whole program but that is because I am from a Java background and you just get used to doing everything by hand. One of the reasons that this question was put on here is because there is a tendency in our company to use MS built in easy click and do, hence nobody could help with the problem as it is all hard coded. I suppose I should ask what I should use instead as I have just looped the results in via a data reader from the Oracle DB? Then returned an array from the data access layer (there are no big queries in this program), the alternative seemed to be a data table or dataset which to my way of thinking are just glorified arrays (but again this could be wrong) your input to my thought would be appreciated. Good or bad, I will take it on the chin and improve if they are bad.

Age is a consequence of experience
 
I await your input with great anxiety

Age is a consequence of experience
 
Perhaps someone else could say why the dataadapter is so bad (as bassguy has not answered) that to use it would restrict employment (I know that bassguy said heavy going but...)cos bassguy has got me thinking(new to C# so do lots of that :) ). If I got all records from a database put them in a dataset and wrote to an xml file (so the database is backed up) taking about 20 lines or so depending on number of tables, then I mention this in my interview, bassguy would not give me a job :( could someone please tell me how I should say I would do this?
Thx T


Age is a consequence of experience
 
But, you didn't mention in your scenerio about using a Data Adapter. The way you populate your DataSet should be less bulky than a DataAdapter. DataAdapters scream drag and drop most of the time.

You can populate a DataSet and write it to XML without a DataAdapter pretty easily.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
thanks for the reply to this.

pretty easily how, please give more information then i know i have an idea what i am looking for. thx again

Age is a consequence of experience
 
As a simple way to populate a Datagrid in ASP.net
{you can set all of the column header data for the grid in the aspx page or in code)

Code:
      DataGrid dgTestGrid = new DataGrid();

      SqlConnection mConn = new SqlConnection("some connection string");
      SqlCommand mCmd = new SqlCommand("Select something from somewhere", mConn);

      mConn.Open();

      dgTestGrid.DataSource = mCmd.ExecuteReader();
      dgTestGrid.DataBind();

      mConn.Close();

To export XML from a Dataset:
(this is admittedly a little bit of a hack job and untested, but is basically the idea)

Code:
      SqlConnection mConn = new SqlConnection("Some connection string");
      SqlCommand mCmd = new SqlCommand("Select something from somewhere", mConn);

      DataTable mDt = new DataTable();
      mDt.Columns.Add(new DataColumn("ThePrimaryKey"));
      mDt.Columns.Add(new DataColumn("TheData"));

      DataSet mDs = new DataSet();
      SqlDataReader mReader;

      mConn.Open();

      mReader = mCmd.ExecuteReader();

      while (mReader.Read())
      {
        DataRow mDr = mDt.NewRow();
        mDr["ThePrimaryKey"] = mReader.GetValue(0);
        mDr["TheData"] = mReader.GetValue(1);
        mDt.Rows.Add(mDr);
      }

      mConn.Close();

      mDs.Tables.Add(mDt);

      string mPath = "your path";

      mDs.WriteXml(mPath);

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
I see, that is a lot clearer but going back to my original post how should I move data from the Data Access Layer to the main form (from one class to another) if I am not to use a DataAdapter in this process. If you could just show me in steps (no code necessary) eg.

Get data with DataReader put into DataTable, return the DataTable.
Or
Get data with DataReader put data into array, then return array.
Or get data with DatReader write to xml file, open xml file from form?
The list goes on...
Thanks for your continued patience and I am sure many people are going to benefit from this as the web is full of howto’s but not many of them state which the best way is.



Age is a consequence of experience
 
Sorry for the lack of responses. I was changing jobs and away from the forum for a bit.

Data adapters do scream of Drag and drop. Also they are designed to handle all of your crud aperations with one object. They do work. They are heavy.

As for what to transfer your dat around with,

The debate still rages depending if you are a java decendant or an ASP / VB decendant.

An OO purist would say that you need to:

Make Connection
Spin through Datareader
Populate collection of objects
return collection




an asp / vb person would say:
Make a table / Dataset and pass that around


I would say that if your app is just a web app with a short shelf life make the tables. if however you need to be able to scale and use OO concepts so that maintaining your app is easier then a collection of objects is more correct.

there are 2 separate camps and they both can be legit answers


hth


bassguy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top