string PID = "T" + DateTime.Now.ToString("yyyyMMddhhmmss") + Convert.ToString(ran.Next(101, 999));
int intCount = this.DataGrid1.Items.Count;
for (int i = 1; i < intCount; i++)
{
string CustType = this.DataGrid1.Items[i].Cells[0].Text;//乘客类型
string Name = this.DataGrid1.Items[i].Cells[1].Text;//乘机人
string CardType = this.DataGrid1.Items[i].Cells[2].Text;//证件类
string CardNo = this.DataGrid1.Items[i].Cells[3].Text;//证件号
string Safe = this.DataGrid1.Items[i].Cells[4].Text;//保险数
string Bprice = this.DataGrid1.Items[i].Cells[5].Text;//保险金额
string TotalPrice = this.DataGrid1.Items[i].Cells[6].Text;//单张票价
string CustNo = this.DataGrid1.Items[i].Cells[7].Text;//常旅客卡
//strcon.Open();
// SqlCommand cmd = new SqlCommand("insert into FlightOrderDetail (OrderId,CustType,Name,CardType,CardNo,CustNo,Price,SafeId,SafePrice) Values ('" + PID + "','" + CustType + "','" + Name + "','" + CardType + "','" + CardNo + "','" + CustNo + "','" + TotalPrice + "''" + Safe + "','" + Bprice + "')", strcon);
//cmd.ExecuteNonQuery();
bc.ExecSQL("insert into FlightOrderDetail (OrderId,CustType,Name,CardType,CardNo,CustNo,Price,SafeId,SafePrice) Values ('" + PID + "','" + CustType + "','" + Name + "','" + CardType + "','" + CardNo + "','" + CustNo + "','" + TotalPrice + "''" + Safe + "','" + Bprice + "')");
}
哪里出问题了.提交的时候数据库里面没内容??
int intCount = this.DataGrid1.Items.Count;
for (int i = 1; i < intCount; i++)
{
string CustType = this.DataGrid1.Items[i].Cells[0].Text;//乘客类型
string Name = this.DataGrid1.Items[i].Cells[1].Text;//乘机人
string CardType = this.DataGrid1.Items[i].Cells[2].Text;//证件类
string CardNo = this.DataGrid1.Items[i].Cells[3].Text;//证件号
string Safe = this.DataGrid1.Items[i].Cells[4].Text;//保险数
string Bprice = this.DataGrid1.Items[i].Cells[5].Text;//保险金额
string TotalPrice = this.DataGrid1.Items[i].Cells[6].Text;//单张票价
string CustNo = this.DataGrid1.Items[i].Cells[7].Text;//常旅客卡
//strcon.Open();
// SqlCommand cmd = new SqlCommand("insert into FlightOrderDetail (OrderId,CustType,Name,CardType,CardNo,CustNo,Price,SafeId,SafePrice) Values ('" + PID + "','" + CustType + "','" + Name + "','" + CardType + "','" + CardNo + "','" + CustNo + "','" + TotalPrice + "''" + Safe + "','" + Bprice + "')", strcon);
//cmd.ExecuteNonQuery();
bc.ExecSQL("insert into FlightOrderDetail (OrderId,CustType,Name,CardType,CardNo,CustNo,Price,SafeId,SafePrice) Values ('" + PID + "','" + CustType + "','" + Name + "','" + CardType + "','" + CardNo + "','" + CustNo + "','" + TotalPrice + "''" + Safe + "','" + Bprice + "')");
}
哪里出问题了.提交的时候数据库里面没内容??
==
楼主,强烈建议使用参数而不是拼接字符串
DataTable dt = new DataTable("TableName");
DataColumn dc1 = new DataColumn("CustType");
DataColumn dc2 = new DataColumn("Name");
DataColumn dc3 = new DataColumn("CardType");
DataColumn dc4 = new DataColumn("CardNo");
DataColumn dc5 = new DataColumn("Safe");
DataColumn dc6 = new DataColumn("Bprice");
DataColumn dc7 = new DataColumn("TotalPrice");
DataColumn dc8 = new DataColumn("CustNo");
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
dt.Columns.Add(dc5);
dt.Columns.Add(dc6);
dt.Columns.Add(dc7);
dt.Columns.Add(dc8);
int AduNum = Convert.ToInt32(Request["AduNum"]);//成人
for (int i = 1; i <= AduNum; i++)
{
DataRow dr1 = dt.NewRow();
dr1[dc1] = Request["AduCustType" + i.ToString()];
dr1[dc2] = Request["AduName" + i.ToString()];
dr1[dc3] = Request["AduCardType" + i.ToString()];
dr1[dc4] = Request["AduCardNo" + i.ToString()];
dr1[dc5] = Request["AduSafe" + i.ToString()];
dr1[dc6] = Request["BNum" + i.ToString()];
dr1[dc7] = Request["TotalAdu"];
dr1[dc8] = Request["AduCustNo" + i.ToString()];
dt.Rows.Add(dr1);
}
int ChiNum = Convert.ToInt32(Request["ChiNum"]);//儿童
for (int i = 1; i <= ChiNum; i++)
{
int bus = Convert.ToInt32(Request["ChiSafe" + i.ToString()]) * 20;
DataRow dr2 = dt.NewRow();
dr2[dc1] = Request["ChiCustType" + i.ToString()];
dr2[dc2] = Request["ChiName" + i.ToString()];
dr2[dc3] = Request["ChiCardType" + i.ToString()];
dr2[dc4] = Request["ChiBirthday" + i.ToString()];
dr2[dc5] = Request["ChiSafe" + i.ToString()];
dr2[dc6] = Request["CNum" + i.ToString()];
dr2[dc7] = Request["TotalChi"];
dt.Rows.Add(dr2);
}
int InfNum = Convert.ToInt32(Request["InfNum"]);//婴儿
for (int i = 1; i <= InfNum; i++)
{
int bus = Convert.ToInt32(Request["InfSafe" + i.ToString()]) * 20;
DataRow dr3 = dt.NewRow();
dr3[dc1] = Request["InfCustType" + i.ToString()];
dr3[dc2] = Request["InfName" + i.ToString()];
dr3[dc3] = "出生日期";
dr3[dc4] = Request["InfBirthday" + i.ToString()];
dr3[dc5] = Request["InfSafe" + i.ToString()];
dr3[dc6] = Request["INum" + i.ToString()];
dr3[dc7] = Request["TotalInf"];
dt.Rows.Add(dr3);
}
this.DataGrid1.DataSource = dt;
this.DataGrid1.DataBind();
用的是这个导入的..