Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1891|回复: 4
打印 上一主题 下一主题

我的asp.net c# coding有问题,帮帮忙!

 关闭 [复制链接]

13

主题

3

好友

1577

积分

白银长老

Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9

跳转到指定楼层
1#
发表于 2010-9-8 06:16 PM |只看该作者 |倒序浏览
public partial class Inventory_ABCAnalysis : System.Web.UI.Page
{
   

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public string testing(int i)
    {
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connString"]);
        string sql = "SELECT COUNT[sellingcost] AS total FROM [Item]";

        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();

        cmd.CommandType = CommandType.Text;

        da.Fill(ds, "Item");
        dt = ds.Tables["Item"];
        
       string category;
        int total;
        total = 100 / dt.Rows[0]["total"];

        if (total * i <= 20)
            category = "A";
        else if (total * i <= 50)
            category = "B";
        else if (total * i <= 100)
            category = "C";
        return category;

    }

}


当我run时,出现以下错误。
Error: Operator '/' cannot be applied to operands of type 'int' and 'object'

由于我一直不能解决这问题,所以才请问各位帮帮忙了,在此感激不尽!




收藏收藏0

8

主题

5

好友

414

积分

翡翠长老

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

2#
发表于 2010-9-8 10:59 PM |只看该作者
回复 1# karen_er30


    total = 100 / dt.Rows[0]["total"];

先convert (dt.Rows[0]["total"])才算


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

3#
发表于 2010-9-9 01:41 AM |只看该作者
unboxing 的问题 楼上的回答了
呵呵


回复

使用道具 举报

13

主题

3

好友

1577

积分

白银长老

Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9

4#
发表于 2010-9-10 01:38 AM |只看该作者
本帖最后由 karen_er30 于 2010-9-10 01:40 AM 编辑

回复 2# j007ha




public partial class Inventory_ABCAnalysis : System.Web.UI.Page
{
   

    protected void Page_Load(object sender, EventArgs e)
    {



    }

    public string testing(int i)
    {
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connString"]);
        string sql = "SELECT COUNT[sellingcost] AS total FROM [Item]";

        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();

        cmd.CommandType = CommandType.Text;

        da.Fill(ds, "Item");
        dt = ds.Tables["Item"];
      
       string category;
      
        int total;
        total = 100 / Convert.ToInt32(dt.Rows[0]["total"]);

        if (total * i <= 20)
            category = "A";
        else if (total * i <= 50)
            category = "B";
        else if (total * i <= 100)
            category = "C";
        return category;

我改了之后,又出现以下问题。
Error: Use of unassigned local variable
是return category出了问题。。


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

5#
发表于 2010-9-13 12:30 PM |只看该作者
教你~这个是小问题。 你放个 Breakpoint 在你的 String Category 那句。 然后 一直next line next line 看你的程式怎么跑的, 你就懂跑的当儿少了什么了。


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-6-26 06:13 PM , Processed in 0.111698 second(s), 27 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部