[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;
}
}
}
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.
Re: Specified Cast Is not valid
try this one.
VB Code:
RCode = dReader.GetValue(0).ToString();
hope that helps.
cheers. :afrog:
Re: Specified Cast Is not valid
Re: Specified Cast Is not valid