使用mysql指定的强制转换是无效的asp.ent。 [英] Specified cast is not valid asp.ent using mysql.

查看:130
本文介绍了使用mysql指定的强制转换是无效的asp.ent。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行我的代码时出现以下错误...请建议..

错误指定演员表无效

I m getting the following error when i execute my code...please suggest..
Error-Specified cast is not valid

long count;
string myScalarQuery = "SHOW TABLES LIKE 'table1';";
MySqlCommand myCommand = new MySqlCommand(myScalarQuery, conn);
conn.Open();
count = (long)myCommand.ExecuteScalar();
conn.Close();
if (count == 0)
  Response.Write("no such table exists");
else
  Response.Write("  "+ count );

推荐答案

ExecuteScalar [ ^ ]返回第一列排' - 为什么你觉得它很长?



[更新作为OP评论的回应]

只查看有多少记录查询返回使用 ExecuteNonQuery [ ^ ] - 它有一个整数返回值,行数。
ExecuteScalar[^] returns the 'first column of the first row' - why do you think it is a long?

[UPDATE AS RESPONSE TO OP COMMENT]
To see only how many records a query returns use ExecuteNonQuery[^] - it has a integer return value, the number of rows.


这篇关于使用mysql指定的强制转换是无效的asp.ent。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆