private void Bind()
{
string id = Session["phoneid"].ToString();
SqlConnection sql = new SqlConnection(con);
sql.Open();
string com = "select *,price*num from cart where phoneid='" + id + "'";
SqlDataAdapter da = new SqlDataAdapter(com,sql);
DataSet ds = new DataSet();
da.Fill(ds);
float count = 0;
foreach (DataRow dr in ds.Tables[0].Rows)
{
count += Convert.ToSingle(dr[6]);
}
M_str_Count = count.ToString();
GridView1.DataSource = ds;
GridView1.DataBind();
sql.Close(); }
请问 count += Convert.ToSingle(dr[4]);中的dr[4]取出来的是什么值,我运行报错的值,我数据表里是没有的
{
string id = Session["phoneid"].ToString();
SqlConnection sql = new SqlConnection(con);
sql.Open();
string com = "select *,price*num from cart where phoneid='" + id + "'";
SqlDataAdapter da = new SqlDataAdapter(com,sql);
DataSet ds = new DataSet();
da.Fill(ds);
float count = 0;
foreach (DataRow dr in ds.Tables[0].Rows)
{
count += Convert.ToSingle(dr[6]);
}
M_str_Count = count.ToString();
GridView1.DataSource = ds;
GridView1.DataBind();
sql.Close(); }
请问 count += Convert.ToSingle(dr[4]);中的dr[4]取出来的是什么值,我运行报错的值,我数据表里是没有的
解决方案 »
- 类似开心的一个个应用是怎么和框架结合的,急急急急急
- 求entity fromwork 增删该查代码 急急急,做毕业设计的,求大家帮忙,万分感谢
- ACCESS不能用OleDbCommandBuilder批量更新数据么?
- 数据库连接问题
- (80分)请教高手。如何用asp.net实现对上传的Word文件的检索
- 使用ms的treeview控件的时候,进入页面时,ie默认会选中第一行数据,有一个烦人的阴影。如何去掉?
- 操作sql server数据库时如何用用存储过程代替普通的insert、update、delete及select操作
- 怎样将十进制的数和二进制的数进行互转?
- DropDownList的聯動問題
- 各位大虾,请问如何在浏览器中显示windows一样的mainmenu
- 获取客户端IP问题
- 相比Java,ASP.NET有没有对应的JSP技术?如何查看一个xxx.aspx对等的 cs文件
数据行(SQL语句中select后的)第5列对应的值,object类型,转换为float
第一,你的列数不够dr[n]取的是第n+1列数据,请确定有这么多列
第二,某一项值为DBNull你可以用if(dr[n]!=DBNull.Value)过滤面对这种情况你可以用DataSet的Compute函数来计算,更省力
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Web.HttpException: DataBinding:“System.Data.DataRowView”不包含名为“userid”的属性。源错误:
行 80: M_str_Count = count.ToString();
行 81: GridView1.DataSource = ds;
行 82: GridView1.DataBind();
行 83: sql.Close();
行 84:
你的SQL写的太烂了。。
把*改成需要的字段名称。。
string com = "select *,price*num from cart where phoneid='" + id + "'";
如:
string com = "select id,xxx1,xxx2,xxx3,xxx4,xxx5,xxx6,price*num from cart where phoneid='" + id + "'";论坛签名======================================================================a161619:你好!
截至 2011-10-23 20:40:15 前:
你已发帖 3 个, 未结贴 1 个;
结贴率为: 66.67%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx