排错~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Gemisum 2006-02-15 10:44:07
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Invoice_Add : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{

//防止外部数据提交的脚本
string sHttp = Request.Headers["referer"];
string sServer = Request.Headers["host"];
if (sServer.Equals(sHttp.Substring(7, sServer.Length)) == false)
{
Response.Write("<script>alert('禁止提交外部数据!');location.href='Invoice_Add.aspx';</script>");
return;
}

SqlConnection myConnection = new SqlConnection("Data Source=Localhost;Initial Catalog=RCMS;User ID=sa;Password=yxgxgs;");
myConnection.Open();

SqlTransaction myTrans = myConnection.BeginTransaction(); //使用New新生成一个事务
SqlCommand myCommand = new SqlCommand();
myCommand.Transaction = myTrans;

string InvoiceIDG = InvoiceID.Text;

string GoodsNameA = GoodsName1.Text;
string UnitPriceA = UnitPrice1.Text;
string UnitA = Unit1.Text;
string QuantityA = Quantity1.Text;
string UnitCTA = UnitCT1.Text;
string CostTypeA = CostType1.Text;
string AmountCTA = AmountCT1.Text;
string AmountA = Amount1.Text;

string GoodsNameB = GoodsName2.Text;
string UnitPriceB = UnitPrice2.Text;
string UnitB = Unit2.Text;
string QuantityB = Quantity2.Text;
string UnitCTB = UnitCT2.Text;
string CostTypeB = CostType2.Text;
string AmountCTB = AmountCT2.Text;
string AmountB = Amount2.Text;

string GoodsNameC = GoodsName3.Text;
string UnitPriceC = UnitPrice3.Text;
string UnitC = Unit3.Text;
string QuantityC = Quantity3.Text;
string UnitCTC = UnitCT3.Text;
string CostTypeC = CostType3.Text;
string AmountCTC = AmountCT3.Text;
string AmountC = Amount3.Text;

string GoodsNameD = GoodsName4.Text;
string UnitPriceD = UnitPrice4.Text;
string UnitD = Unit4.Text;
string QuantityD = Quantity4.Text;
string UnitCTD = UnitCT4.Text;
string CostTypeD = CostType4.Text;
string AmountCTD = AmountCT4.Text;
string AmountD = Amount4.Text;

string GoodsNameE = GoodsName5.Text;
string UnitPriceE = UnitPrice5.Text;
string UnitE = Unit5.Text;
string QuantityE = Quantity5.Text;
string UnitCTE = UnitCT5.Text;
string CostTypeE = CostType5.Text;
string AmountCTE = AmountCT5.Text;
string AmountE = Amount5.Text;

string GoodsNameF = GoodsName6.Text;
string UnitPriceF = UnitPrice6.Text;
string UnitF = Unit6.Text;
string QuantityF = Quantity6.Text;
string UnitCTF = UnitCT6.Text;
string CostTypeF = CostType6.Text;
string AmountCTF = AmountCT6.Text;
string AmountF = Amount6.Text;

try
{

AddSource1.Insert();

myCommand.CommandText = "INSERT INTO [Invoice_Detail] ([InvoiceID], [GoodsName], [UnitPrice], [Unit], [Quantity], [UnitCT], [CostType], [AmountCT], [Amount], [NBBH]) VALUES ('" + InvoiceIDG + "', '" + GoodsNameA + "', '" + UnitPriceA + "', '" + UnitA + "', '" + QuantityA + "', '" + UnitCTA + "', '" + CostTypeA + "', '" + AmountCTA + "', '" + AmountA + "')";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "INSERT INTO [Invoice_Detail] ([InvoiceID], [GoodsName], [UnitPrice], [Unit], [Quantity], [UnitCT], [CostType], [AmountCT], [Amount], [NBBH]) VALUES ('" + InvoiceIDG + "', '" + GoodsNameB + "', '" + UnitPriceB + "', '" + UnitB + "', '" + QuantityB + "', '" + UnitCTB + "', '" + CostTypeB + "', '" + AmountCTB + "', '" + AmountB + "')";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "INSERT INTO [Invoice_Detail] ([InvoiceID], [GoodsName], [UnitPrice], [Unit], [Quantity], [UnitCT], [CostType], [AmountCT], [Amount], [NBBH]) VALUES ('" + InvoiceIDG + "', '" + GoodsNameC + "', '" + UnitPriceC + "', '" + UnitC + "', '" + QuantityC + "', '" + UnitCTC + "', '" + CostTypeC + "', '" + AmountCTC + "', '" + AmountC + "')";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "INSERT INTO [Invoice_Detail] ([InvoiceID], [GoodsName], [UnitPrice], [Unit], [Quantity], [UnitCT], [CostType], [AmountCT], [Amount], [NBBH]) VALUES ('" + InvoiceIDG + "', '" + GoodsNameD + "', '" + UnitPriceD + "', '" + UnitD + "', '" + QuantityD + "', '" + UnitCTD + "', '" + CostTypeD + "', '" + AmountCTD + "', '" + AmountD + "')";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "INSERT INTO [Invoice_Detail] ([InvoiceID], [GoodsName], [UnitPrice], [Unit], [Quantity], [UnitCT], [CostType], [AmountCT], [Amount], [NBBH]) VALUES ('" + InvoiceIDG + "', '" + GoodsNameE + "', '" + UnitPriceE + "', '" + UnitE + "', '" + QuantityE + "', '" + UnitCTE + "', '" + CostTypeE + "', '" + AmountCTE + "', '" + AmountE + "')";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "INSERT INTO [Invoice_Detail] ([InvoiceID], [GoodsName], [UnitPrice], [Unit], [Quantity], [UnitCT], [CostType], [AmountCT], [Amount], [NBBH]) VALUES ('" + InvoiceIDG + "', '" + GoodsNameF + "', '" + UnitPriceF + "', '" + UnitF + "', '" + QuantityF + "', '" + UnitCTF + "', '" + CostTypeF + "', '" + AmountCTF + "', '" + AmountF + "')";
myCommand.ExecuteNonQuery();

myTrans.Commit();

}
catch (Exception ex)
{
myTrans.Rollback();
Response.Write("<script>alert('" + ex.ToString() + "');location.href='Invoice_Add.aspx';</script>");
}
finally
{
myConnection.Close();
Response.Write("<script>alert('操作成功!');location.href='Invoice_Add.aspx';</script>");
}

}

}
...全文
53 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gemisum 2006-02-15
  • 打赏
  • 举报
回复
na zengme juejie ne?
Gemisum 2006-02-15
  • 打赏
  • 举报
回复
o xiexie !
hedongfu 2006-02-15
  • 打赏
  • 举报
回复
你把 Response.Write("<script>alert('操作成功!');location.href='Invoice_Add.aspx';</script>");
放到Finally里,那不管成功不成功都会显示操作成功
Gemisum 2006-02-15
  • 打赏
  • 举报
回复
提交成功的对话框出现了~可数据库却没有数据
Gemisum 2006-02-15
  • 打赏
  • 举报
回复
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????help me ~

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧