Re: SQLClient SQLAdapter Data type problem



"Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx> wrote in
news:#RqTpBXCHHA.1196@xxxxxxxxxxxxxxxxxxxx:

rj wrote:
I'm having problems simply retrieving values from the database and
using in their original format. Example below assumes that size
column is double or float
Here is code snippet:

string maxSize;
string source = "Data Source=server_name; Initial Catalog=testing;
User ID=bj; Password=pass";
SqlConnection conn = new SqlConnection(source);
string select = "select max(size) from sizes";
SqlAdapter da new SqlAdapter(select, conn);
DataSet ds = new DataSet();
da.Fill(ds, "maxSize");

foreach(DataRow in ds.Tables["maxSize"].Rows)
{

maxSize = row[0].ToString();
}

Everything works here but how I go about it if I need maxSize to be
double or float? if I do maxSize = (double)row[0]; I get "cannot
explicitly convert object to double" There is something I don't quite
understand. And if query returns only one row, how can I get the size
value without using foreach?


There was no way for you to know it (except maybe by browsing through
some of the previous questions in this newsgroup before posting yours
- always a recommended practice) , but this is a classic ADO
newsgroup. ADO.Net bears very little resemblance to classic ADO so,
while you may be lucky enough to find a dotnet-knowledgeable person
here who can answer your question, you can eliminate the luck factor
by posting your question to a group where those dotnet-knowledgeable
people hang out. I suggest microsoft.public.dotnet.framework.adonet.

Having said that, I'm not sure why you are using a dataset for this
purpose. Use a SQLCommand and SQLDataReader. The ExecuteReader method
has an argument to allow you to specify that the query is returning a
single row.

As to maxSize, I'm not sure why you need to convert the value to
double in order to store it in a string variable.
What are you trying to accomplish?

Thanks for the response. I'll post message to the group you
recommended.
Just to clarify things: My point was that it always works if I use
string variable with ToString, but there is no ToFloat if I want it to
be float and perform math operations on it.

Thanks

.



Relevant Pages

  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... to strcmpwhich expects a pointer to a string. ... And now a question about something else: why do you use floating ... int,float, char, etc. ...
    (comp.lang.c)
  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... And now a question about something else: why do you use floating ... use then to copy a float into a char *1. ... binary representation doesn't resemble a string like "123.46343" ...
    (comp.lang.c)
  • Re: How to marshall "pointer to pointer"
    ... UInt16 Layer, ByteInstanceName, float X, float Y, BytePath, IntPtr ... DstPath); ... IntPtr and pass it it Marshal.PtrToStringBSTR() to get this string. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: help with Table Macro
    ... Available Float, which will always be in column ... string contained in that cell. ... test phrase "available float". ... next matching word and repeat the process until no more matching words ...
    (microsoft.public.word.application.errors)
  • Re: Qbersetzung_von_C_nach_VB?=
    ... FILE_HEADER ist eine Präprozessor-Konstante mit dem Inhalt ... Reserve As String * 32 ... Open As Double ' float könnte auch Single sein *grübel* ... Die Daten mit Hilfe eines Byte-Arrays der passenden Länge ...
    (microsoft.public.de.vb)