[英]error CS0266: Cannot implicitly convert type 'object' to 'int'
error CS0266: Cannot implicitly convert type 'object' to 'int'.
错误CS0266:无法将类型'object'隐式转换为'int'。 An explicit conversion exists (are you missing a cast?)
存在显式转换(您是否错过了演员?)
int dd= 6000;
sqlCmdDefaultTime = new SqlCommand("myQuery", sqlCon);
sqlDefaultTime = sqlCmdDefaultTime.ExecuteReader();
while (sqlDefaultTime.Read())
{
dd= sqlDefaultTime[1];
}
how can i cast 我怎么能投
简单转换为int
:
dd = (int)sqlDefaultTime[1];
Try this... 尝试这个...
int.TryParse(sqlDefaultTime[1].ToString(), out dd);
in the event that the parse is successful dd
will now be a new value. 如果解析成功,
dd
现在将是一个新值。
Unless of course the object is an int already, the you can just cast it... 当然除非对象已经是int,你可以把它投出来......
dd = (int)sqlDefaultTime[1];
Instead of the indexer try to use the GetXXX methods of SqlDataReader: 而不是索引器尝试使用SqlDataReader的GetXXX方法:
dd = sqlDefaultTime.GetInt32(1);
More GetXXX methods here: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx 这里有更多GetXXX方法: http : //msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx
Integer.parseInt(); 的Integer.parseInt();
a few others such as TryParse and TryParseExact provide more functionality and control. 其他一些如TryParse和TryParseExact提供了更多的功能和控制。
dd= Integer.parseInt(sqlDefaultTime[1]);
should do it, provided you can guarantee the value being returned is always an int. 应该这样做,只要你能保证返回的值总是一个int。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.