我试着去接受一个字符串转换为整数,代码是这样的:如何转换避免System.FormatException的数据类型?
int menu = 3
int orden = 0;
string query = @"select max(oppord)+1 as orden
from rhlibry.vaoppfi
where pincor = " + menu;
OdbcConnection cn = new OdbcConnection("dsn=RHLIBRY;uid=PC00;pwd=PC00;");
OdbcCommand cmd = new OdbcCommand(query, cn);
cn.Open();
OdbcDataReader oa = cmd.ExecuteReader();
while (oa.Read())
{
orden = Int32.Parse(oa["orden"].ToString());
}
return orden;
以字符串格式SQL查询返回“奥登”,我需要转换成整型。
行orden = Int32.Parse(oa["orden"].ToString());
返回System.FormatException类型的错误。
为什么?我做错了?
请帮帮我!
谢谢
什么是'oppord'的数据类型? –
stephen,数据类型是数字(8,0)在数据库中 –
您在该表中有任何记录吗?这可能是因为oa [“orden”]是'DBNull.Value' –