asp.net中如果使用Sql语句查询的值
int a;string sum = "Select Sum(VoteID) as mcount From Votes";
SqlCommand Comm = new SqlCommand(sum, Conn);
string count1 = "Select Count(fine) From Votes Where fine=1";
SqlCommand Comm1 = new SqlCommand(count1, Conn);
a = (Int64)count1 / (Int64)sum;
在VS2008里面写的,数据库有连接打开,可是系统提示:无法将string转换成long、;还有个问题是,调试发现“Select Sum(VoteID) as mcount From Votes”得到的值没有赋给左边。这是为什么呢。。。求救求救。。。 --------------------编程问答-------------------- int a;
string sum = "Select Sum(VoteID) as mcount From Votes";
SqlCommand Comm = new SqlCommand(sum, Conn);
string count1 = "Select Count(fine) From Votes Where fine=1";
SqlCommand Comm1 = new SqlCommand(count1, Conn);
a = (Int64)count1 / (Int64)sum;
=======
你好歹也看下书在敲代码吧
你认为2个string相除可以获得什么? --------------------编程问答-------------------- sqlcommand都还没执行呢。
声明string类型别用关键字sum
a=int.Parse( comm1.ExecuteScalar() )/int.Parse( comm1.ExecuteScalar() );
--------------------编程问答-------------------- 你再看书吧,要是书上还是这样的话。
建议:不要看这 本书了,因为这本书太不负责任了。
--------------------编程问答-------------------- a=int.Parse( comm1.ExecuteScalar() )/int.Parse( comm.ExecuteScalar() );
后面的应该没有1 --------------------编程问答-------------------- SqlCommand cmd = new SqlCommand("Select Sum(VoteID) as mcount From Votes", Conn);
int sum=Convert.ToInt32(cmd.ExecuteScalar());
cmd.CommandText="Select Count(fine) From Votes Where fine=1";
int count=Convert.ToInt32(cmd.ExecuteScalar());
int a=count/sum;
或者double a=(double)count/sum;
--------------------编程问答--------------------
建议看一下ADO。NET吧,看看怎么读取数据库中的数据,SqlDataReader,SqlDataAdapter,SqlCommand这几个对象重点掌握
补充:.NET技术 , ASP.NET