本文整理汇总了C#中System.Data.OleDb.OleDbDataAdapter.Update方法的典型用法代码示例。如果您正苦于以下问题:C# OleDbDataAdapter.Update方法的具体用法?C# OleDbDataAdapter.Update怎么用?C# OleDbDataAdapter.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.OleDb.OleDbDataAdapter
的用法示例。
在下文中一共展示了OleDbDataAdapter.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: searcher
public void searcher(string field, string column)
{
try
{
connectionString = ConfigurationManager.AppSettings["DBConnectionString"] + frmHomeScreen.mUserFile;
string query = "select ISBN, Title, Author, Publisher, Binding, pub_date as Publication_Date, Pages, Available from book where " + column + " like '%" + escapeHandling(field) + "%' order by Author, Title;";
OleDbDataAdapter da = new OleDbDataAdapter(query, connectionString);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
DataTable dt = new DataTable();
da.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dgvBook.DataSource = bs;
da.Update(dt);
databaseHandler d = new databaseHandler();
d.closeDatabaseConnection();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
dgvBook.ClearSelection();
}
示例2: Button3_Click
protected void Button3_Click(object sender, EventArgs e)
{
if (this.IsValid)
{
string con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("App_data/db1.mdb");
OleDbConnection ole = new OleDbConnection(con);
DataSet ds = new DataSet();
DataRow drow;
ole.Open();
OleDbDataAdapter oda = new OleDbDataAdapter("select * from yonghu", con);
OleDbCommandBuilder ob = new OleDbCommandBuilder(oda);
oda.Fill(ds, "tab");
int num = ds.Tables["tab"].Rows.Count;
drow = ds.Tables["tab"].NewRow();
drow[0] = num + 1;
num++;
drow[1] = TextBox2.Text;
drow[2] = TextBox3.Text;
ds.Tables["tab"].Rows.Add(drow);
oda.Update(ds, "tab");
ole.Close();
this.Panel3.Visible = false;
this.Label2.Visible = true;
this.Label3.Visible = true;
this.Button4.Visible = true;
}
}
示例3: Delete
/// <summary>Delete the specified Cause from the specified Issue.</summary>
/// <param name="pIssueID">ID of the Issue the cause applies to.</param>
/// <param name="pCauseID">ID of the Cause to delete.</param>
/// <returns>ID of the modified/created cause row.</returns>
public void Delete(int pIssueID, int pCauseID)
{
try
{
using(OleDbDataAdapter oDA = new OleDbDataAdapter(String.Format("Select * from Causes where issue_id = {0} and cause_id = {1} order by cause_seq", pIssueID, pCauseID), this.DataObject.ConnectionString))
using(OleDbCommandBuilder oCB = new OleDbCommandBuilder(oDA))
using(OleDbConnection oConn = new OleDbConnection(this.DataObject.ConnectionString))
{
// Get the list of previously saved Causes to the current Issue.
oConn.Open();
DataSet oDS = new DataSet("Causes");
oDA.Fill(oDS);
// If we found any...And we're updating an existing Cause...
if(oDS.Tables[0].Rows.Count > 0)
{
DataRow oRow = oDS.Tables[0].Rows[0];
oRow.Delete();
oDA.Update(oDS);
}
}
}
catch(Exception e)
{
throw new Exception("Unable to save new Issue Cause!\nError: " + e.Message);
}
}
示例4: frmWhatMedia_Load
private void frmWhatMedia_Load(object sender, EventArgs e)
{
try
{
string connectionString = ConfigurationManager.AppSettings["DBConnectionString"] + frmHomeScreen.mUserFile;
string query = "select Title, isbn as Checkout_Code from (select title, isbn from book union select title, upc from movie union select title,upc from game union select album,upc from cd) order by title;";
OleDbDataAdapter da = new OleDbDataAdapter(query, connectionString);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
DataTable dt = new DataTable();
da.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dgvMedia.DataSource = bs;
da.Update(dt);
databaseHandler d = new databaseHandler();
d.closeDatabaseConnection();
DataGridViewColumn c = dgvMedia.Columns[0];
c.Width = 155;
dgvMedia.ClearSelection();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
示例5: clears
private void clears()
{
txtNameSearch.Text = "Enter all or part of a name here...";
txtCCSearch.Text = "Scan a customer card here...";
try
{
connectionString = ConfigurationManager.AppSettings["DBConnectionString"] + frmHomeScreen.mUserFile;
string query = "select * from customer order by last_name;";
OleDbDataAdapter da = new OleDbDataAdapter(query, connectionString);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
DataTable dt = new DataTable();
da.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dgvCustomers.DataSource = bs;
da.Update(dt);
databaseHandler d = new databaseHandler();
d.closeDatabaseConnection();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
示例6: Main
static void Main(string[] args)
{
//dateTime.DataSet1TableAdapters.table1TableAdapter table = new dateTime.DataSet1TableAdapters.table1TableAdapter();
//table.Insert("arif", "khan", "hasan", "1988-01-10", "100.00");
//Console.ReadLine();
OleDbConnection con = new OleDbConnection(@"Provider=VFPOLEDB.1;Data Source=D:\Documents and Settings\axkhan2\Desktop\table\table1.dbf");
con.Open();
OleDbDataAdapter adapt = new OleDbDataAdapter(@"select * from 'D:\Documents and Settings\axkhan2\Desktop\table\table1.dbf'", con);
OleDbCommandBuilder build = new OleDbCommandBuilder(adapt);
DataSet set = new DataSet();
adapt.Fill(set);
DataTable table = set.Tables[0];
DataRow row = table.NewRow();
row["firstname"] = "arifkhan";
row["lastname"] = "khan";
row["middlename"] = "mname";
row["dob"] = DateTime.Now;
row["amount"] = 100;
table.Rows.Add(row);
//adapt.Update(table);
//adapt.UpdateCommand = build.GetUpdateCommand();
adapt.Update(table);
//cmd.ExecuteNonQuery();
}
示例7: Button1_Click1
protected void Button1_Click1(object sender, EventArgs e)
{
string username=this.TextBox1.Text;
string con="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+System.Web.HttpContext.Current.Server.MapPath("App_data/db1.mdb");
OleDbConnection ole=new OleDbConnection(con);
DataSet ds=new DataSet();
DataRow drow;
ole.Open();
OleDbCommand olec=new OleDbCommand("select * from yonghu where yname='"+username+"'",ole);
int count=Convert.ToInt32(olec.ExecuteScalar());
OleDbDataAdapter oda=new OleDbDataAdapter ("select * from yonghu",ole);
OleDbCommandBuilder ob=new OleDbCommandBuilder(oda);
oda.Fill(ds,"tab");
if (count > 0)
{
this.Label1.Text = "昵称已存在,请重新输入!";
}
else
{
drow = ds.Tables["tab"].NewRow();
drow[0] = ds.Tables["tab"].Rows.Count + 1;
drow[1] = this.TextBox1.Text;
ds.Tables["tab"].Rows.Add(drow);
oda.Update(ds, "tab");
ole.Close();
Session["name"] = Request["TextBox1"];
Application["message"] = "";
Response.Redirect("HTMLPage.htm");
}
}
示例8: DataTableInsert
/// <summary>
/// 插入数据通过Datatable
/// </summary>
/// <param name="_dt"></param>
/// <returns>影响记录条数</returns>
public override int DataTableInsert(DataTable _dt)
{
bool flag = false;
int _nResult = 0;
if (_dt == null)
return _nResult;
string _sCmdText = string.Format("select * from {0} where 1=2", _dt.TableName);
OleDbCommand _Command = (OleDbCommand)CreateCommand(_sCmdText, CommandType.Text);
OleDbDataAdapter _adapter = new OleDbDataAdapter(_Command);
OleDbDataAdapter _adapter1 = new OleDbDataAdapter(_Command);
OleDbCommandBuilder _builder = new OleDbCommandBuilder(_adapter1);
_adapter.InsertCommand = _builder.GetInsertCommand();
if (_adapter.InsertCommand.Parameters.Count < _dt.Columns.Count)
{
flag = true;//因为表中有自增字段,所以CommandBuild生成的InserttCommand的参数中少了自增字段
foreach (DataColumn _dc in _dt.Columns)
{
if (!_adapter.InsertCommand.Parameters.Contains(_dc.ColumnName))
{
_adapter.InsertCommand.CommandText =
_adapter.InsertCommand.CommandText.Insert(_adapter.InsertCommand.CommandText.IndexOf(") VALUES"), ',' + _dc.ColumnName);
_adapter.InsertCommand.CommandText =
_adapter.InsertCommand.CommandText.Insert(_adapter.InsertCommand.CommandText.Length - 1, ",?");
_adapter.InsertCommand.Parameters.Add("@" + _dc.ColumnName, OleDbType.Decimal, _dc.MaxLength, _dc.ColumnName);
if (_adapter.InsertCommand.Parameters.Count >= _dt.Columns.Count)
break;
}
}
}
if (flag)
this.ExecuteNoQuery(string.Format("SET IDENTITY_INSERT {0} on", _dt.TableName));
this.BeginTransaction();
try
{
_adapter.InsertCommand.Transaction = _Command.Transaction;
_Command.CommandText = "delete from " + _dt.TableName;
_Command.ExecuteNonQuery();
_nResult = _adapter.Update(_dt);
this.CommitTransaction();
}
catch (Exception ex)
{
this.RollbackTransaction();
throw ex;
}
finally
{
if (flag)
this.ExecuteNoQuery(string.Format("SET IDENTITY_INSERT {0} OFF", _dt.TableName));
}
return _nResult;
}
示例9: Gravar
public void Gravar(DataSet ds, string tabela)
{
OleDbCommandBuilder cmdBuilder;
OleDbDataAdapter adaptador;
adaptador = new OleDbDataAdapter("select * from " + tabela, conexão);
cmdBuilder = new OleDbCommandBuilder(adaptador);
adaptador.Update(ds, tabela);
}
示例10: CapNhatBang
public static void CapNhatBang(DataSet ds)
{
OleDbConnection cn = DataProvider.ConnectionData();
string strSQL = "Select * From LoaiSach";
OleDbDataAdapter da = new OleDbDataAdapter(strSQL, cn);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
da.Update(ds.Tables[0]);
//B5: Dong ket noi CSDL
cn.Close();
}
示例11: Main
public static void Main(string[] args)
{
WriteToEventLog("Calling AEPM Service...");
var dt = new DataTable();
var dset = new DataSet();
Guid = args[0];
//retrieve any records needing updating
try
{
using(var conn = new OleDbConnection(ConfigurationManager.AppSettings["AS400ConnectionStringDev"]))
{
string sql = GetUnprocessMasterRecsString();
var objDataAdapter = new OleDbDataAdapter();
var cmd = new OleDbCommand(sql, conn);
objDataAdapter.SelectCommand = cmd;
objDataAdapter.SelectCommand.CommandTimeout = 0;
dt.Clear();
dset.Clear();
objDataAdapter.Fill(dt);
objDataAdapter.Fill(dset, "currentSelections");
var cb = new OleDbCommandBuilder(objDataAdapter);
AddParameters(cb);
//update records to 'S' for submitted
for (int i = 0; i < dset.Tables["currentSelections"].Rows.Count; i++)
{
dset.Tables["currentSelections"].Rows[i]["G_RETRN"] = 'S';
}
objDataAdapter.Update(dset, "currentSelections");
//submit records asynch
for (int i = 0; i < dt.Rows.Count; i++)
{
TestAsync(dt, i);
}
}
}
catch (Exception ex)
{
WriteToEventLog(ex);
}
}
示例12: Main
public static void Main(string [] str)
{
string path = "D:\\temp\\csc\\dataset";
string table = path+"\\temp.dbf";
OleDbConnection con = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=D:\\temp\\csc\\dataset");
con.Open();
try
{
OleDbDataAdapter da = new OleDbDataAdapter("select * from "+table, con);
// da.SelectCommand = new OleDbCommand("select * from "+table, con);
da.UpdateCommand = new OleDbCommand("update "+ table+"set fname = ? where id = 1", con);
da.UpdateCommand.Parameters.Add("fname", OleDbType.VarChar, 200, "@fname");
da.UpdateCommand.Parameters.Add("fname", OleDbType.VarChar, 200, "@fname").SourceVersion = DataRowVersion.Original;
DataTable tb = new DataTable();
da.Fill(tb);
/* DataSet ds = new DataSet();
da.Fill(ds);
DataTable tb = ds.Tables[0];
DataRow rw = tb.NewRow();
rw["id"] = 4;
rw["fname"] = "afreen";
rw["lname"] = "khan";
rw["mname"] = "arif";
*/
// tb.Rows.Add(rw);
Console.WriteLine("Enter you first name");
DataRow rw = tb.Rows[0];
rw["fname"] = Console.ReadLine();
// Console.WriteLine("row added to table");
// OleDbCommandBuilder build = new OleDbCommandBuilder(da);
da.Update(tb);
Console.WriteLine("Table updated");
}
catch(OleDbException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
con.Close();
}
}
示例13: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("app_data/db1.mdb");
OleDbConnection ole = new OleDbConnection(strconn);
DataSet ds = new DataSet();
DataRow drow;
ole.Open();
OleDbDataAdapter oda = new OleDbDataAdapter("select * from yh", strconn);
OleDbCommandBuilder ob = new OleDbCommandBuilder(oda);
oda.Fill(ds, "tab");
drow = ds.Tables["tab"].NewRow();
drow[0] = Session["yname"];
drow[1] = this.TextBox1.Text;
ds.Tables["tab"].Rows.Add(drow);
oda.Update(ds, "tab");
DataList1.DataSource = ds.Tables["tab"];
DataList1.DataBind();
ole.Close();
}
示例14: deleteToolStripMenuItem_Click
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
string row = dgvMovies[0, dgvMovies.CurrentRow.Index].Value.ToString();
if (MessageBox.Show("Are you sure?", "Confirm Deletion", MessageBoxButtons.YesNo) == DialogResult.No) {
MessageBox.Show("Request ignored");
dgvMovies.ClearSelection();
return;
}
try {
connectionString = ConfigurationManager.AppSettings["DBConnectionString"] + frmHomeScreen.mUserFile;
string query = "delete from Movie where UPC = '" + row + "';";
string query2 = "delete from Actor where UPC = '" + row + "';";
OleDbDataAdapter da = new OleDbDataAdapter(query, connectionString);
OleDbDataAdapter da2 = new OleDbDataAdapter(query2, connectionString);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
OleDbCommandBuilder cb2 = new OleDbCommandBuilder(da2);
DataTable dt = new DataTable();
da.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dgvMovies.DataSource = bs;
da.Update(dt);
}
catch (Exception ex) {
MessageBox.Show("Unexpected error: " + ex);
}
finally {
databaseHandler d = new databaseHandler();
d.closeDatabaseConnection();
}
refresh();
dgvMovies.ClearSelection();
}
示例15: Write
public void Write(CubeMetadata metadata)
{
if (metadata == null)
throw new ArgumentNullException();
GetSheets();
if (_sheets.IndexOf(SheetName + "$") == -1)
CreateNewSheet(SheetName);
RaiseProgressStatus("Opening Xls file");
DataTable dataTable = MetadataFileFormat.WriteInDataTable(metadata);
dataTable.TableName = SheetName + "$";
_rowTotal = dataTable.Rows.Count;
using (var conn = new OleDbConnection(GetConnectionString(Filename)))
{
using (var da = new OleDbDataAdapter())
{
var sb = new StringBuilder();
sb.AppendFormat("INSERT INTO [{0}$] (", SheetName);
foreach (DataColumn col in dataTable.Columns)
sb.AppendFormat(" {0},", col.ColumnName);
sb.Remove(sb.Length - 1, 1); //Remove the last comma
sb.Append(") VALUES (");
for (int i = 0; i < dataTable.Columns.Count; i++)
sb.Append(" ?,");
sb.Remove(sb.Length - 1, 1); //Remove the last comma
sb.Append(")");
da.InsertCommand = new OleDbCommand(sb.ToString(), conn);
foreach (DataColumn col in dataTable.Columns)
da.InsertCommand.Parameters.Add(string.Format("@{0}", col.ColumnName), OleDbType.VarChar, 255, col.ColumnName);
da.RowUpdated += new OleDbRowUpdatedEventHandler(OnRowUpdated);
conn.Open();
da.Update(dataTable);
da.RowUpdated -= new OleDbRowUpdatedEventHandler(OnRowUpdated);
}
}
RaiseProgressStatus("Xls file written");
}