On the line date=(int) datamanager.ExecuteScalar(CommandType.Text, Query);
I am getting an error saying:
Error converting data type varchar to numeric.
In the GETEDITDATE
query I'm trying to retrieve data that is of type varchar
. How do I resolve this issue?
Code:
public string returneditdate(string receiptid, string ConString) {
string Query = string.Empty;
int date = 0;
string dat = string.Empty;
DataManager datamanager = null;
try {
datamanager = Supporter.GetDataManager();
datamanager.ConnectionString = ConString;
datamanager.Open();
Query = DataSourceSQLConstants.GETEDITDATE.Replace("@fldreceiptid", receiptid.ToString());
date = (int) datamanager.ExecuteScalar(CommandType.Text, Query);
dat = date.ToString();
}
}
If it's a varchar datatype, it is text. You need to use int.Parse
method to convert it to a integer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.