c# datagridview 批量修改,做一个按钮对修改后的数据更新到数据库,找高手解决
3个回答
展开全部
public DataSet UpInfo(DataSet table, String tableName)
{
string connString = "data source=oraksjh;User ID=u_ksjh;Password=smksjh;Integrated Security=no";
OracleConnection conn = new OracleConnection(connString);
OracleTransaction trans = null ;
try
{
string cmdText = "SELECT 番号,名前,电话,住所,性别,入社时间 FROM " + tableName;
OracleCommand cmd = new OracleCommand(cmdText, conn);
conn.Open();
trans = conn.BeginTransaction();
OracleDataAdapter rar = new OracleDataAdapter();
rar.SelectCommand = cmd;
cmd.Transaction = trans;
//rar.Fill(table, tableName);
OracleCommandBuilder cmdBuilder = new OracleCommandBuilder(rar);
if (table.HasChanges())
{
rar.Update(table.Tables[tableName]);
trans.Commit();
}
conn.Close();
}
catch (Exception e)
{
e.ToString();
trans.Rollback();
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
return table;
}
{
string connString = "data source=oraksjh;User ID=u_ksjh;Password=smksjh;Integrated Security=no";
OracleConnection conn = new OracleConnection(connString);
OracleTransaction trans = null ;
try
{
string cmdText = "SELECT 番号,名前,电话,住所,性别,入社时间 FROM " + tableName;
OracleCommand cmd = new OracleCommand(cmdText, conn);
conn.Open();
trans = conn.BeginTransaction();
OracleDataAdapter rar = new OracleDataAdapter();
rar.SelectCommand = cmd;
cmd.Transaction = trans;
//rar.Fill(table, tableName);
OracleCommandBuilder cmdBuilder = new OracleCommandBuilder(rar);
if (table.HasChanges())
{
rar.Update(table.Tables[tableName]);
trans.Commit();
}
conn.Close();
}
catch (Exception e)
{
e.ToString();
trans.Rollback();
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
return table;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询