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
|