About DataTable.Roes.Find

T

Tony

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
 
A

Arne Vajhøj

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top