朋友们还是不成,各种方法都用了数据库表的ID也是int类型,真不知该怎么办了,不会是设成自动增长标识列造成的吧
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class addxzflower : System.Web.UI.Page
{
private static string connectionString = "server=.;uid=sa;pwd=1;database=flowershops";
yyjDAL.WebClass cl = new yyjDAL.WebClass();
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["Username"].ToString();
if (!IsPostBack)
{
GridView1.DataKeyNames = new String[] { "st_name" };
this.GridView1.DataSource = cl.GetAllxx();
this.GridView1.DataBind(); }
if (!IsPostBack)
{ DataTable newdtb = new DataTable();
newdtb.Columns.Add("st_id", typeof(int));
newdtb.Columns.Add("st_name", typeof(string));
newdtb.Columns.Add("ST_Price", typeof(string));
newdtb.Columns.Add("ST_Sales", typeof(string));
newdtb.Columns.Add("ST_Type", typeof(string));
newdtb.Columns["st_name"].AutoIncrement = true; }
}
protected void Button1_Click(object sender, EventArgs e)
{ DataTable newdtb = new DataTable();
newdtb.Columns.Add("st_name", typeof(string));
newdtb.Columns.Add("ST_Price", typeof(string));
newdtb.Columns.Add("ST_Sales", typeof(string));
newdtb.Columns.Add("ST_Type", typeof(string)); newdtb.Columns["st_name"].AutoIncrement = true; foreach (GridViewRow item in GridView1.Rows)
{
CheckBox chkID = (CheckBox)item.FindControl("CheckBox1");
if (chkID.Checked == true && item.RowType == DataControlRowType.DataRow)
{
DataRow newRow = newdtb.NewRow();
newRow["st_id"] = int.Parse(item.Cells[0].Text);
newRow["st_name"] = item.Cells[1].Text.ToString();
newRow["ST_Price"] = item.Cells[2].Text.ToString();
newRow["ST_Sales"] = item.Cells[3].Text.ToString();
newRow["ST_Type"] = item.Cells[4].Text.ToString();
newdtb.Rows.Add(newRow);
}
}
GridView2.DataSource = newdtb;
GridView2.DataBind();
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class addxzflower : System.Web.UI.Page
{
private static string connectionString = "server=.;uid=sa;pwd=1;database=flowershops";
yyjDAL.WebClass cl = new yyjDAL.WebClass();
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["Username"].ToString();
if (!IsPostBack)
{
GridView1.DataKeyNames = new String[] { "st_name" };
this.GridView1.DataSource = cl.GetAllxx();
this.GridView1.DataBind(); }
if (!IsPostBack)
{ DataTable newdtb = new DataTable();
newdtb.Columns.Add("st_id", typeof(int));
newdtb.Columns.Add("st_name", typeof(string));
newdtb.Columns.Add("ST_Price", typeof(string));
newdtb.Columns.Add("ST_Sales", typeof(string));
newdtb.Columns.Add("ST_Type", typeof(string));
newdtb.Columns["st_name"].AutoIncrement = true; }
}
protected void Button1_Click(object sender, EventArgs e)
{ DataTable newdtb = new DataTable();
newdtb.Columns.Add("st_name", typeof(string));
newdtb.Columns.Add("ST_Price", typeof(string));
newdtb.Columns.Add("ST_Sales", typeof(string));
newdtb.Columns.Add("ST_Type", typeof(string)); newdtb.Columns["st_name"].AutoIncrement = true; foreach (GridViewRow item in GridView1.Rows)
{
CheckBox chkID = (CheckBox)item.FindControl("CheckBox1");
if (chkID.Checked == true && item.RowType == DataControlRowType.DataRow)
{
DataRow newRow = newdtb.NewRow();
newRow["st_id"] = int.Parse(item.Cells[0].Text);
newRow["st_name"] = item.Cells[1].Text.ToString();
newRow["ST_Price"] = item.Cells[2].Text.ToString();
newRow["ST_Sales"] = item.Cells[3].Text.ToString();
newRow["ST_Type"] = item.Cells[4].Text.ToString();
newdtb.Rows.Add(newRow);
}
}
GridView2.DataSource = newdtb;
GridView2.DataBind();
}
解决方案 »
- (又一难题)----- 还是关于数组的循环的问题,请各位前辈帮帮我 -----
- 指点下我写的代码?
- winform程序占用资源一多,就会无声无息自动关闭消失。这个问题能解决吗?
- 什么是应用程序域(要求简明易懂的答案)
- 关于在C#下调用ORACLE存储过程!
- 难道CSDN真的C#.Net方面的没有高手吗?
- 控件问题 求如何解决
- 为什么我的C#没有DataGrid.HitTestInfo这个功能?(没分了,大家帮帮我)
- 如何安装VISUAL STUDIO。NET?
- 我现在已经基本学会了C#的语法,请问接下去该如果学习比较好?
- 求助:winform 中 Datagridview 中的下拉控件绑定默认值
- Mysql动态创建数据库
int.TryParse判断
SET IDENTITY_INSERT
允许将显式值插入表的标识列中。语法
SET IDENTITY_INSERT [ database.[ owner.] ] { table } { ON | OFF }
newRow["st_id"] = int.Parse(item.Cells[0].Text);
注释掉.
newRow["st_id"] = int.Parse(item.Cells[0].Text);
注释掉.
谢谢大家