还是不成
朋友们还是不成,各种方法都用了数据库表的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();
}
[解决办法]
贴出 gridview值看看
int.TryParse判断
[解决办法]
问题咧。?
标识列在没有设定以下选项时是不能显示插入值的
SET IDENTITY_INSERT
允许将显式值插入表的标识列中。
语法
SET IDENTITY_INSERT [ database.[ owner.] ] { table } { ON
[解决办法]
OFF }
[解决办法]
你数据库中ID是主键吗?自动增长,那你程序里面就不需要对他进行赋值操作了呀.
newRow["st_id"] = int.Parse(item.Cells[0].Text);
注释掉.
[解决办法]
谢谢已解决
[解决办法]
楼主,你解决了之后,就不能把解决问题的方法说出来吗。
这样得话,帮你的同学,都白忙活了。唉。。。。。
[解决办法]
你数据库中ID是主键吗?自动增长,那你程序里面就不需要对他进行赋值操作了呀.
newRow["st_id"] = int.Parse(item.Cells[0].Text);
注释掉.
谢谢大家