|
-
May 2nd, 2005, 02:27 AM
#1
Thread Starter
Addicted Member
[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
-
May 2nd, 2005, 12:46 PM
#2
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.
-
May 2nd, 2005, 10:07 PM
#3
Hyperactive Member
Re: Specified Cast Is not valid
try this one.
VB Code:
RCode = dReader.GetValue(0).ToString();
hope that helps.
cheers.
-
May 3rd, 2005, 12:50 AM
#4
Thread Starter
Addicted Member
Re: Specified Cast Is not valid
-
May 10th, 2005, 05:52 AM
#5
Thread Starter
Addicted Member
Re: Specified Cast Is not valid
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|