Results 1 to 5 of 5

Thread: [RESOLVED] Specified Cast Is not valid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    141

    Resolved [RESOLVED] Specified Cast Is not valid

    when we run this code with Debug.WriteLine Generate No error
    when we run this code with dReader.GetValue/GetString Generate Error Specified Cast Is not valid In Database field datatype also Varchar

    public string GetID(string strQuery)
    {
    SqlDataReader dReader=null;
    string RCode="";
    try
    {
    dReader = FillDataReader(strQuery,dReader);
    if (dReader.Read())
    {
    //Debug.WriteLine(dReader.GetValue(0));
    RCode = (string)dReader.GetValue(0);
    return RCode;
    }
    }


    }
    Last edited by Waseemalisyed; May 10th, 2005 at 06:31 AM. Reason: ok

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: Specified Cast Is not valid

    Console.WriteLine will work because it is overloaded; it accepts all data types.

    Copy the dReader.GetValue(0) line, excluding the cast, to the immediate window when code execution reaches there; it should display the type that was returned.

  3. #3
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: Specified Cast Is not valid

    try this one.
    VB Code:
    1. RCode = dReader.GetValue(0).ToString();
    hope that helps.
    cheers.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    141

    Resolved Re: Specified Cast Is not valid

    thanks For ur Coperation

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    141

    Resolved Re: Specified Cast Is not valid

    thanks for ur coperation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width