指定演员表无效 [英] specified cast is invalid
本文介绍了指定演员表无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我是编程新手。学习c#,asp.net。
写一个简单的程序:从数据库中获取id并将其保存到arraylist中以找到max(id)。
并获得异常:指定的演员表无效。
at line:int low =(int)arrm [i];
感谢任何帮助。
谢谢
Hi
I am new to programming. learning c# , asp.net.
write a simple program: to get the id from database and save it to arraylist to find the max(id).
and getting exception: Specified cast is invalid.
at line: int low = (int)arrm[i];
Appreciate any help.
Thanks
推荐答案
Hi
我是编程新手。学习c#,asp.net。
写一个简单的程序:从数据库中获取id并将其保存到arraylist中以找到max(id)。
并获得异常:指定的演员表无效。
at line:int low =(int)arrm [i];
感谢任何帮助。
谢谢
Hi
I am new to programming. learning c# , asp.net.
write a simple program: to get the id from database and save it to arraylist to find the max(id).
and getting exception: Specified cast is invalid.
at line: int low = (int)arrm[i];
Appreciate any help.
Thanks
是你的桌子还是行?
如果是表,则arrm [i]是一行,
也许你想要的是
is arrm your table or the row?
if it is the table then arrm[i] is a row,
maybe what you want is
展开 | 选择 | 换行 | 行号
arram是一个对象我的数组列表。
Arraylist arrm =新的Arraylist();
这里是我脚本的一部分:
cmd4.CommandText =" select from dpt" ;
cmd4.ExecuteNonQuery();
SqlDataReader reader = cmd4.ExecuteReader();
while(reader.Read())
{
values = new object [reader.FieldCount];
reader.GetValues(values);
arrm.Add (值);
}
arrm.Sort();
reader.Close();
cmd4 .Connection.Close();
int max = 0;
for(int i = 0; i< arrm.Count; i ++)
{
int min =(int)arrm [i];
if(max< min)
max = min;
}
}
谢谢,
arram is a object of my array list.
Arraylist arrm = new Arraylist();
and here is part of my script:
cmd4.CommandText = "select id from dpt" ;
cmd4.ExecuteNonQuery();
SqlDataReader reader = cmd4.ExecuteReader();
while(reader.Read())
{
values = new object[reader.FieldCount];
reader.GetValues(values);
arrm.Add(values);
}
arrm.Sort();
reader.Close();
cmd4.Connection.Close();
int max = 0;
for (int i = 0; i < arrm.Count; i++)
{
int min = (int)arrm[i];
if (max < min)
max = min;
}
}
Thanks,
您可以在arrm [i]上使用.GetType()。Name来查看实际返回的值的类型。
如果ID定义为say,我猜" BIGINT"在数据库中,您需要将其强制转换为Int64。而不仅仅是int
You could use the .GetType().Name on the arrm[i] to see what type the value is actually being returned as.
I would guess that if ID is defined as say "bigint" in the database, you would need to cast it to "Int64" and not just "int"
这篇关于指定演员表无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文