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'
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出了问题。。作者: 宅男-兜着走 时间: 2010-9-13 12:30 PM
教你~这个是小问题。 你放个 Breakpoint 在你的 String Category 那句。 然后 一直next line next line 看你的程式怎么跑的, 你就懂跑的当儿少了什么了。