PC Review


Reply
Thread Tools Rate Thread

About DataTable.Roes.Find

 
 
Tony
Guest
Posts: n/a
 
      24th Dec 2011
Hello!

In this code snipped I lookup a DataRow based on the defined primary key in
the DataTable Customers that is located in the Northwind database.
This may seems like a strange question but I ask it anyway and that is
according to the documentation the Find method takes an object. But
everything is an object for example the generic class List<T> is an object.
So I mean when the Find takes an object it should be more clear if it would
mention that it must be of a value type because that is an requirement
except for string in this case.

Is this correct understood ?

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);
string strSQL = "select CustomerID, CompanyName from Customers";
SqlDataAdapter da = new SqlDataAdapter(strSQL, con);
da.TableMappings.Add("Table", "Customers");
DataSet ds = new DataSet();
da.FillSchema(ds, SchemaType.Source,"Customers");
da.Fill(ds,"Customers");
DataRow row = ds.Tables["Customers"].Rows.Find("ALFKI");
}

//Tony

 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      2nd Jan 2012
On 12/24/2011 7:25 AM, Tony wrote:
> In this code snipped I lookup a DataRow based on the defined primary key
> in the DataTable Customers that is located in the Northwind database.
> This may seems like a strange question but I ask it anyway and that is
> according to the documentation the Find method takes an object. But
> everything is an object for example the generic class List<T> is an object.
> So I mean when the Find takes an object it should be more clear if it
> would mention that it must be of a value type because that is an
> requirement except for string in this case.
>
> Is this correct understood ?
>
> protected void Page_Load(object sender, EventArgs e)
> {
> SqlConnection con = new SqlConnection(connectionString);
> string strSQL = "select CustomerID, CompanyName from Customers";
> SqlDataAdapter da = new SqlDataAdapter(strSQL, con);
> da.TableMappings.Add("Table", "Customers");
> DataSet ds = new DataSet();
> da.FillSchema(ds, SchemaType.Source,"Customers");
> da.Fill(ds,"Customers");
> DataRow row = ds.Tables["Customers"].Rows.Find("ALFKI");
> }


Fundamentally ordinary data sets are not type safe.

This "issue" is just a manifestation of that fact.

If you want to be type safe, the chose something else
than DataSet.

Arne

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:19 PM.