I am trying to build a C#.net program that works like a RPG Subfile on the AS400.
我正在尝试构建一个C#.net程序,它就像AS400上的RPG子文件一样。
Have the general subfile part working. I can display and then edit and update existing records.
让一般子文件部分工作。我可以显示然后编辑和更新现有记录。
Am blowing up in my code where I am trying to insert a new record. Blowing up on the
在我试图插入新记录的代码中爆炸。炸毁了
cmd.ExecuteNonQuery();
If you want to see how this works without the insert go to
如果你想看看如何在没有插入的情况下工作
Look at the Website1a
看看Website1a
Here is the code.
这是代码。
using IBM.Data.DB2.iSeries;
using System;
using System.Data;
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 WebForm3 : System.Web.UI.Page
{
protected void btnBack_Click(object sender, EventArgs e)
{
Server.Transfer("WebForm1a.aspx");
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
ConnectionStringSettingsCollection cssc =
ConfigurationManager.ConnectionStrings;
String connString = cssc["FTWAS400"].ToString();
iDB2Connection conn = new iDB2Connection(connString);
conn.Open();
iDB2Command cmd = new iDB2Command(
"insert into tburrows.qcustcdt (cusnum, init, lstnam, street, city, state, zipcod, cdtlmt, chgcod, baldue, cdtdue) values (@cusnum, @init, @lstnam, @street, @city, @state, @zipcod, @cdtlmt, @chgcod, @baldue, @cdtdue)", conn);
cmd.DeriveParameters();
cmd.Parameters["@cusnum"].Value = Request["txtCUSNUM"];
cmd.Parameters["@init" ].Value = Request["txtINIT"];
cmd.Parameters["@lstnam"].Value = Request["txtLSTNAM"];
cmd.Parameters["@street"].Value = Request["txtSTREET"];
cmd.Parameters["@city"].Value = Request["txtCITY"];
cmd.Parameters["@state"].Value = Request["txtSTATE"];
cmd.Parameters["@zipcod"].Value = Request["txtZIPCOD"];
cmd.Parameters["@cdtlmt"].Value = Request["txtCDTLMT"];
cmd.Parameters["@chgcod"].Value = Request["txtCHGCOD"];
cmd.Parameters["@baldue"].Value = Request["txtBALDUE"];
cmd.Parameters["@cdtdue"].Value = Request["txtCDTDUE"];
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
btnBack_Click(sender, e);
}
}
Any help will greatly be appreciated.
任何帮助将不胜感激。
Thomas
1 个解决方案
#1
3
There is another option within the
内有另一种选择
cmd.Parameters["@cusnum"].Value = field;
to specify the field type. Use
指定字段类型。使用
cmd.Parameters.Add("@cusnum", iDB2DbType.iDB2Decimal).Value = Convert.ToDecimal(field);
instead. This should convert your data types properly. You will need to change the iDB2Decimal to the proper field type if not decimal.
代替。这应该正确转换您的数据类型。如果不是十进制,您将需要将iDB2Decimal更改为正确的字段类型。
#1
3
There is another option within the
内有另一种选择
cmd.Parameters["@cusnum"].Value = field;
to specify the field type. Use
指定字段类型。使用
cmd.Parameters.Add("@cusnum", iDB2DbType.iDB2Decimal).Value = Convert.ToDecimal(field);
instead. This should convert your data types properly. You will need to change the iDB2Decimal to the proper field type if not decimal.
代替。这应该正确转换您的数据类型。如果不是十进制,您将需要将iDB2Decimal更改为正确的字段类型。