dataset problem

    Date: 06/12/06 (C Sharp)    Keywords: database, sql

    I’m currently working with C# and SQLExpress 2005, and I’m doing some database stuff.

    I have a table that has two columns, [Index] and Descriptor. It looks like:

    0 Inactive
    1 Active
    etc.



    Relevant code:

    DataSet DS2 = new DataSet();

    //cbostatus is a combo box containing a list of descriptors that the user can choose from

    string getstat = "SELECT [Index] FROM status WHERE Descriptor = '" + cboStatus.Text + "';";

    conn.Open();
    SqlDataAdapter stat = new SqlDataAdapter(getstat, conn);
    stat.Fill(DS2);

    //The stat.Fill command should return a single value, since the sql query only returns 1 value

    int status = Convert.ToInt32((DS2.Tables[0].Rows[0]));

    // This is where I get an error, and the error is "InvalidCastException was unhandled Unable to cast object of type 'System.Data.DataRow' to type 'System.IConvertible'."

    conn.Close();


    Any ideas on how I can get this to return an int, or convert the dataset element to an int?

    Thanks!

    Source: http://community.livejournal.com/csharp/65023.html

« SQL INSERT || TableAdapters and mapping... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home