none
How to retrieve the field having datatype varchar & characterset OCTETS... RRS feed

  • Question

  • When I try with the following code having datatype varchar, it will retrieve in textBox3

     

    string connectionString = "userid=SYSDBA;password=masterkey;database = mydb.FDB";

    string commandText = "select username from users";

    FbDataAdapter da = new FbDataAdapter(commandText, connectionString);

    DataSet ds = new DataSet();

    da.Fill(ds, "USERS");

    textBox3.Text = ds.Tables[0].Rows[0]["username"].ToString();

     

    But the above code is not working incase of the field Passwd_MD5 having datatype varchar & characterset OCTETS.

    as follows:-

    string connectionString = "userid=SYSDBA;password=masterkey;database = mydb.FDB";

    string commandText = "select passwd_MD5 from users";

    FbDataAdapter da = new FbDataAdapter(commandText, connectionString);

    DataSet ds = new DataSet();

    da.Fill(ds, "USERS");

    textBox3.Text = ds.Tables[0].Rows[0]["passwd_MD5"].ToString();

     

    Please suggest me how i can retrieve the passwd_MD5 field from the database.

     

    with regards

    Tapan

    Wednesday, June 13, 2007 10:15 AM

All replies

  • Your problem isn't with retrieving the field, it's with displaying what you've retrieved.  If you look at your DataTable in the debugger, you'll almost certainly find that the passwd_MD5 column is, in .Net, of type System.Byte[].

    You can't just convert System.Byte[] to String via ToString(); you need to use something like the ASCIIEncoding class.  Basically, you need to provide the converter with knowledge about what it should be doing to translate bytes with values above 127 to UTF-16 characters.

    If all you want is to verify that you're actually retrieving something, just cast the column to byte[], iterate through its elements, and write them out, e.g.

       foreach (byte b in (byte[])ds.Tables[0].Rows[0]["passwd_MD5"])
       {
          Console.Write("{0} ", (int)b);
       }
    Saturday, June 16, 2007 8:33 AM