这个不算太好,写个方法作try catch 判断返回值
解决方案 »
- GDO+中出现一般性错误
- 急 System.NullReferenceException: 未将对象引用设置到对象的实例。
- 这句是什么意思!!!!
- vs2005连接SQL的问题,安装VS2005时没装SQL2005可以吗?
- 页面排版问题,郁闷....
- 请教各位如何清理浏览器缓存?
- 水晶报表的安装
- 如何将二维数组转换成DataTable
- 请问,如何在CodeBehind模式下解决对前端HTML元素的javascript脚本事件的响应函数的指定啊?
- response.redirect的问题
- 请问下这种treegrid控件(TreeView + DataGrid的效果)如何实现?谢谢
- full join是什么意思?full join和full outer join有什么区别?有outer和没outer的链接有什么不同?
for (i=0;i<dtb.Rows.Count;i++)
{ if (dtb.Rows(i)("userId")==userId) //此行出错!
{
Response.Write("已经存在");
}
else
{
Response.Write("bu存在");
}
}
错误 1 “System.Data.DataTable.Rows”是“属性”,但此处被当做“方法”来使用
用正则表达式应该会快些的
{if (dtb.Rows[i]["userId"]==userId) //此行出错!
{
Response.Write("已经存在");
}
else
{
Response.Write("bu存在");
}
}
if(drs.Length >0)
{
//有此 userId
}
{if (dtb.Rows[i]["userId"]==userId+"") //此行出错!
{
Response.Write("已经存在");
}
else
{
Response.Write("bu存在");
}
}
加了个+"" 就不用toint转换了。
DataRows[] drs = dtb.Select("userID="+userId.ToString());//忘记看类型了
//DataRows[] drs = dtb.Select("userID="+userId.ToString()+" and (userSex ='"+userSex +"'" +" or userName='"+userName+"')");//举一反三
if(drs.Length >0)
{
//有此 userId
}
{
if (IsPostBack)
{
int userId = Convert.ToInt32(this.DetailsView1.Rows[0].Cells[1].Text);
string userName = this.DetailsView1.Rows[1].Cells[1].Text.ToString();
string userSex = this.DetailsView1.Rows[4].Cells[1].Text.ToString();
//DataSet ds = new DataSet();
DataTable dtb = new DataTable("MyCar");
dtb.Columns.Add("userId", typeof(int));
dtb.Columns.Add("userName");
dtb.Columns.Add("userSex");
dtb.Columns.Add("TheCount"); int a = 1;
DataRow dRow = dtb.NewRow();
dRow["userId"] = userId;
dRow["userName"] = userName;
dRow["userSex"] = userSex;
dRow["TheCount"] = a;
DataRow[] drs = dtb.Select("userID=" + userId);
if (drs.Length > 0)
{
a+=1;
}
else
{
a = 1;
} dtb.Rows.Add(dRow); Session["myCar"] = dtb; this.DetailsView2.DataSource = (DataTable)Session["myCar"];
this.DetailsView2.DataBind(); this.Gv2.DataSource = dtb.DefaultView;
this.Gv2.DataBind(); }
{
DataTable dtb = Session["myCar"] as DataTable;
if(dtb==null)
{
//DataSet ds = new DataSet();
DataTable dtb = new DataTable("MyCar");
dtb.Columns.Add("userId", typeof(int));
dtb.Columns.Add("userName");
dtb.Columns.Add("userSex");
dtb.Columns.Add("TheCount");
}
if (IsPostBack)
{
int userId = Convert.ToInt32(this.DetailsView1.Rows[0].Cells[1].Text);
string userName = this.DetailsView1.Rows[1].Cells[1].Text.ToString();
string userSex = this.DetailsView1.Rows[4].Cells[1].Text.ToString();
int a = 1;
DataRow dRow = dtb.NewRow();
dRow["userId"] = userId;
dRow["userName"] = userName;
dRow["userSex"] = userSex;
//dRow["TheCount"] = a; DataRow[] drs = dtb.Select("userID=" + userId);
if (drs.Length > 0)
{
a+=1;
}
else
{
a = 1;
}
dRow["TheCount"] = a; //在这赋值
dtb.Rows.Add(dRow); Session["myCar"] = dtb; this.DetailsView2.DataSource = (DataTable)Session["myCar"];
this.DetailsView2.DataBind(); this.Gv2.DataSource = dtb.DefaultView;
this.Gv2.DataBind(); }
dv.Rowfile = "想要过滤信息";
{ int goodsId = Int32.Parse(this.DetailsView1.Rows[0].Cells[1].Text);
string theGoodsName = (this.DetailsView1.Rows[1].Cells[1].Text).ToString();
decimal thePrice = Convert.ToDecimal(this.DetailsView1.Rows[5].Cells[1].Text); //DataTable dtb = Session["myCar"] as DataTable;
// DataTable dtb = new DataTable("MyCar");
if (Session["myCar"] == null)
{
//DataSet ds = new DataSet();
DataTable dtb = new DataTable("MyCar");
dtb.Columns.Add("goodsId", typeof(int));
dtb.Columns.Add("thtGoodsName");
dtb.Columns.Add("thtPrice");
dtb.Columns.Add("TheCount"); DataRow dRow = dtb.NewRow();
dRow["goodsId"] = goodsId;
dRow["thtGoodsName"] = theGoodsName;
dRow["thtPrice"] = thePrice;
dRow["TheCount"] = 1;
dtb.Rows.Add(dRow); Session["myCar"] = dtb;
} else
{
DataTable dtb = Session["myCar"] as DataTable;
//dtb.Columns.Add("goodsId", typeof(int));
int a = 1;
DataRow[] drs = dtb.Select("goodsId=" + goodsId);
if (drs.Length > 0)
{
a += 1;
//怎样将 a 的值写入 DataTable dtb 而不需要添加新行!
//DataRow[] drs = dtb.Rows[goodsId];
} else
{
a = 1;
DataRow dRow = dtb.NewRow();
dRow["goodsId"] = goodsId;
dRow["thtGoodsName"] = theGoodsName;
dRow["thtPrice"] = thePrice;
dRow["TheCount"] = a;
dtb.Rows.Add(dRow);
} Session["myCar"] = dtb;
this.DetailsView2.DataSource = dtb;
this.DetailsView2.DataBind();
}
}
if (drs.Length > 0)
{
a += 1;
//怎样将 a 的值写入 DataTable dtb 而不需要添加新行!
drs[0]["TheCount"] = a;
}
{}
else
{}