110,538
社区成员
发帖
与我相关
我的任务
分享
OdbcConnection odbcConn = new OdbcConnection(strOdbcConn);
string strSQL = "select top 1 * from order order by dono";
OdbcDataAdapter odbcDA = new OdbcDataAdapter(strSQL, odbcConn);
OdbcCommandBuilder builder = new OdbcCommandBuilder(odbcDA);
odbcDA.InsertCommand = builder.GetInsertCommand();
odbcDA.Update(ds, "Order");
DataSet2 ds = new DataSet2();
DataRow dr = ds.Tables["Order"].NewRow();
dr["dono"] = "999999999";
dr["cuno"] = "CF";
dr["cuorno"] = "CF0001";
dr["cupdno"] = "CF_X001";
dr["mcbomno"] = "YH_Test_001";
dr["dollno"] = "1";
dr["price"] = (Decimal)99.99;
dr["term"] = "No Pay No Matter";
dr["vol"] = (Decimal)1000;
dr["totm"] = (Decimal)9999.00;
dr["outvol"] = (Decimal)0;
dr["bavol"] = (Decimal)0;
dr["nopy"] = (Decimal)999;
dr["mono"] = "No Mono to Say";
dr["orday"] = DateTime.Now;
dr["pyday"] = DateTime.Now.AddDays(10);
dr["dqno"] = "US";
dr["puchday"] = DateTime.Now;
dr["puchname"] = "WJC";
dr["modiday"] = DateTime.Parse("1900-01-01");
dr["modiname"] = "";
dr["outaddress"] = "Bright";
dr["yesno"] = false;
dr["fw"] = false;
dr["fprice"] = (Decimal)0.00;
dr["mkcuno"] = "yhbr";
dr["type"] = 1;
dr["cbprice"] = (Decimal)11.11;
dr["cbdollno"] = "1";
dr["ywno"] = "";
dr["partno"] = "";
dr["amark"] = "";
dr["bmark"] = "";
dr["cmark"] = "";
ds.Tables["Order"].Rows.Add(dr);
OdbcConnection odbcConn = new OdbcConnection(strOdbcConn);
string strSQL = "select top 1 * from Order order by dono";
OdbcDataAdapter odbcDA = new OdbcDataAdapter(strSQL, odbcConn);
//OdbcCommandBuilder builder = new OdbcCommandBuilder(odbcDA);
//odbcDA.InsertCommand = builder.GetInsertCommand();
//odbcDA.Update(ds, "Order");
string sqlorder = "INSERT INTO Order (dono, cuno, cuorno, cupdno, mcbomno, dollno, price, term, vol, totm, outvol, bavol, nopy," +
" mono, orday, pyday, dqno, puchday, puchname, modiday, modiname, ywno, partno, outaddress, yesno, amark, bmark, cmark, fw," +
" fprice, mkcuno, type, cbprice, cbdollno) VALUES " +
"(?, ?, ?, ?, ?, ?, " +
((decimal)ds.Order.Rows[0]["price"]).ToString("0.0000") + ", ?," +
((decimal)ds.Order.Rows[0]["vol"]).ToString("0") + ", " +
((decimal)ds.Order.Rows[0]["totm"]).ToString("0.00") + ", " +
((decimal)ds.Order.Rows[0]["outvol"]).ToString("0") + ", " +
((decimal)ds.Order.Rows[0]["bavol"]).ToString("0") + ", " +
((decimal)ds.Order.Rows[0]["nopy"]).ToString("0") + ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " +
((decimal)ds.Order.Rows[0]["fprice"]).ToString("0.0000") + ", ?, ?, " +
((decimal)ds.Order.Rows[0]["cbprice"]).ToString("0.0000") + ", ?)";
odbcDA.InsertCommand = new OdbcCommand(sqlorder, odbcConn);
for (int i = 0; i < ds.Order.Columns.Count; i++)
{
OdbcType mytype = new OdbcType();
if (ds.Order.Columns[i].DataType != typeof(decimal))
{
if (ds.Order.Columns[i].DataType == typeof(string))
{
mytype = System.Data.Odbc.OdbcType.NVarChar;
}
if (ds.Order.Columns[i].DataType == typeof(global::System.DateTime))
{
mytype = System.Data.Odbc.OdbcType.Date;
}
if (ds.Order.Columns[i].DataType == typeof(bool))
{
mytype = System.Data.Odbc.OdbcType.Bit;
}
OdbcParameter para;
para = odbcDA.InsertCommand.Parameters.Add(new OdbcParameter("@" + ds.Order.Columns[i].ColumnName, mytype));
para.SourceColumn = ds.Order.Columns[i].ColumnName;
}
}
odbcDA.Update(ds, "Order");
private void button1_Click( object sender, EventArgs e )
{
OleDbConnection conn = new OleDbConnection( @"Provider=vfpoledb.1;Data Source=D:\VFP98;Collating Sequence=machine;" );
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from Test";
OleDbDataAdapter oda = new OleDbDataAdapter( cmd );
DataSet ds = new DataSet();
oda.Fill( ds, "test" );
DataTable dt = ds.Tables[0];
DataRow dr = dt.NewRow();
dr["iid"] = 1;
dr["name"] = "abc";
dr["english"] = 3.75;
dr["math"] = 1834.4483;
dt.Rows.Add( dr );
OleDbCommandBuilder ocb = new OleDbCommandBuilder( oda );
oda.InsertCommand = ocb.GetInsertCommand();
oda.Update( ds, "test" );
conn.Close();
}