个人想法:我把5条数据同时放入dataset中,然后再直接DataAdatapter.Update,可否?
18 个解决方案
#1
当然可以。
#2
按你说的,可以
放入dataset中可以用循环
放入dataset中可以用循环
#3
你可以对dataset进行多次更改,然后保存。
#4
具体该怎么操作,还有问题就是,我这5条数据里面有可能只需要插入4条数据,需要判断一下是否有空数据
#5
public DataSet CreateCmdsAndUpdate(DataSet myDataSet,string myConnection,string mySelectQuery,string myTableName)
{
OleDbConnection myConn = new OleDbConnection(myConnection);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();
myDataAdapter.SelectCommand = new OleDbCommand(mySelectQuery, myConn);
OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter);
myConn.Open();
DataSet custDS = new DataSet();
myDataAdapter.Fill(custDS);
//code to modify data in dataset here
myDataAdapter.Update(custDS, myTableName);
myConn.Close();
return custDS;
}
{
OleDbConnection myConn = new OleDbConnection(myConnection);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();
myDataAdapter.SelectCommand = new OleDbCommand(mySelectQuery, myConn);
OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter);
myConn.Open();
DataSet custDS = new DataSet();
myDataAdapter.Fill(custDS);
//code to modify data in dataset here
myDataAdapter.Update(custDS, myTableName);
myConn.Close();
return custDS;
}
#6
怎么用循环啊?如果插入值是规则的,那有可能用循环,但是如果非规则的值呢?能不能说详细点~~~
#7
先检测,有的话,再循环。
#8
作循环把五条记录分别写入数据集,再更新就可以了。
#9
同意lhx1977(清水无鱼)
#10
在更新数据库前可以用DataSet的GetChanges()函数获取插入的数据。
DataSet dataset2=dataset1.GetChanges(DataRowState.Added);
DataSet dataset2=dataset1.GetChanges(DataRowState.Added);
#11
反正Insert这个SQL是不行的,要一个一个的用,我想DataSet里面一定也是一个循环吧......
#12
Insert into totable (column01,column02)
slect * from fromtable (column11,column12)
slect * from fromtable (column11,column12)
#13
先放入DataSet再插入数据库
#14
to: bitsbird(一瓢.net) 这样还是有问题的嘛,使用DataAdapter.Update(ds,table)的时候抱错啊
#15
SELECT col1,col2,,,
INTO ToTable
FROM FromTable
Where 条件
INTO ToTable
FROM FromTable
Where 条件
#16
up
#17
//被SaveExcelToDb()调用,开始一个事务,将ArrayList中的SQL语句全部执行。
private string SaveToOracle(ArrayList al)
{
string bv;
string connStr=System.Configuration.ConfigurationSettings.AppSettings["Oracle"];
OracleConnection oraConn=new OracleConnection(connStr);
OracleCommand oraComm= new OracleCommand();
oraComm.Connection = oraConn;
oraConn.Open();
OracleTransaction oraTrans;
// Start a local transaction
oraTrans = oraConn.BeginTransaction(IsolationLevel.ReadCommitted);
// Assign transaction object for a pending local transaction
oraComm.Transaction = oraTrans;
try
{
for(int i=0;i<al.Count;i++)
{
oraComm.CommandText= (string) al[i];
oraComm.ExecuteNonQuery();
}
oraTrans.Commit();
bv = "成功写入数据库";
}
catch(Exception err)
{
oraTrans.Rollback();
bv = err.Message;
}
finally
{
oraConn.Close();
}
return bv;
}
一条一条的执行insert语句,可以的。
private string SaveToOracle(ArrayList al)
{
string bv;
string connStr=System.Configuration.ConfigurationSettings.AppSettings["Oracle"];
OracleConnection oraConn=new OracleConnection(connStr);
OracleCommand oraComm= new OracleCommand();
oraComm.Connection = oraConn;
oraConn.Open();
OracleTransaction oraTrans;
// Start a local transaction
oraTrans = oraConn.BeginTransaction(IsolationLevel.ReadCommitted);
// Assign transaction object for a pending local transaction
oraComm.Transaction = oraTrans;
try
{
for(int i=0;i<al.Count;i++)
{
oraComm.CommandText= (string) al[i];
oraComm.ExecuteNonQuery();
}
oraTrans.Commit();
bv = "成功写入数据库";
}
catch(Exception err)
{
oraTrans.Rollback();
bv = err.Message;
}
finally
{
oraConn.Close();
}
return bv;
}
一条一条的执行insert语句,可以的。
#18
up
#1
当然可以。
#2
按你说的,可以
放入dataset中可以用循环
放入dataset中可以用循环
#3
你可以对dataset进行多次更改,然后保存。
#4
具体该怎么操作,还有问题就是,我这5条数据里面有可能只需要插入4条数据,需要判断一下是否有空数据
#5
public DataSet CreateCmdsAndUpdate(DataSet myDataSet,string myConnection,string mySelectQuery,string myTableName)
{
OleDbConnection myConn = new OleDbConnection(myConnection);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();
myDataAdapter.SelectCommand = new OleDbCommand(mySelectQuery, myConn);
OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter);
myConn.Open();
DataSet custDS = new DataSet();
myDataAdapter.Fill(custDS);
//code to modify data in dataset here
myDataAdapter.Update(custDS, myTableName);
myConn.Close();
return custDS;
}
{
OleDbConnection myConn = new OleDbConnection(myConnection);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter();
myDataAdapter.SelectCommand = new OleDbCommand(mySelectQuery, myConn);
OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter);
myConn.Open();
DataSet custDS = new DataSet();
myDataAdapter.Fill(custDS);
//code to modify data in dataset here
myDataAdapter.Update(custDS, myTableName);
myConn.Close();
return custDS;
}
#6
怎么用循环啊?如果插入值是规则的,那有可能用循环,但是如果非规则的值呢?能不能说详细点~~~
#7
先检测,有的话,再循环。
#8
作循环把五条记录分别写入数据集,再更新就可以了。
#9
同意lhx1977(清水无鱼)
#10
在更新数据库前可以用DataSet的GetChanges()函数获取插入的数据。
DataSet dataset2=dataset1.GetChanges(DataRowState.Added);
DataSet dataset2=dataset1.GetChanges(DataRowState.Added);
#11
反正Insert这个SQL是不行的,要一个一个的用,我想DataSet里面一定也是一个循环吧......
#12
Insert into totable (column01,column02)
slect * from fromtable (column11,column12)
slect * from fromtable (column11,column12)
#13
先放入DataSet再插入数据库
#14
to: bitsbird(一瓢.net) 这样还是有问题的嘛,使用DataAdapter.Update(ds,table)的时候抱错啊
#15
SELECT col1,col2,,,
INTO ToTable
FROM FromTable
Where 条件
INTO ToTable
FROM FromTable
Where 条件
#16
up
#17
//被SaveExcelToDb()调用,开始一个事务,将ArrayList中的SQL语句全部执行。
private string SaveToOracle(ArrayList al)
{
string bv;
string connStr=System.Configuration.ConfigurationSettings.AppSettings["Oracle"];
OracleConnection oraConn=new OracleConnection(connStr);
OracleCommand oraComm= new OracleCommand();
oraComm.Connection = oraConn;
oraConn.Open();
OracleTransaction oraTrans;
// Start a local transaction
oraTrans = oraConn.BeginTransaction(IsolationLevel.ReadCommitted);
// Assign transaction object for a pending local transaction
oraComm.Transaction = oraTrans;
try
{
for(int i=0;i<al.Count;i++)
{
oraComm.CommandText= (string) al[i];
oraComm.ExecuteNonQuery();
}
oraTrans.Commit();
bv = "成功写入数据库";
}
catch(Exception err)
{
oraTrans.Rollback();
bv = err.Message;
}
finally
{
oraConn.Close();
}
return bv;
}
一条一条的执行insert语句,可以的。
private string SaveToOracle(ArrayList al)
{
string bv;
string connStr=System.Configuration.ConfigurationSettings.AppSettings["Oracle"];
OracleConnection oraConn=new OracleConnection(connStr);
OracleCommand oraComm= new OracleCommand();
oraComm.Connection = oraConn;
oraConn.Open();
OracleTransaction oraTrans;
// Start a local transaction
oraTrans = oraConn.BeginTransaction(IsolationLevel.ReadCommitted);
// Assign transaction object for a pending local transaction
oraComm.Transaction = oraTrans;
try
{
for(int i=0;i<al.Count;i++)
{
oraComm.CommandText= (string) al[i];
oraComm.ExecuteNonQuery();
}
oraTrans.Commit();
bv = "成功写入数据库";
}
catch(Exception err)
{
oraTrans.Rollback();
bv = err.Message;
}
finally
{
oraConn.Close();
}
return bv;
}
一条一条的执行insert语句,可以的。
#18
up