本文整理汇总了C#中MySql.Data.MySqlClient.MySqlCommandBuilder类的典型用法代码示例。如果您正苦于以下问题:C# MySqlCommandBuilder类的具体用法?C# MySqlCommandBuilder怎么用?C# MySqlCommandBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MySqlCommandBuilder类属于MySql.Data.MySqlClient命名空间,在下文中一共展示了MySqlCommandBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MySqlTableContext
public MySqlTableContext( DataTable dataTable, MySqlConnection connection )
{
this.Connection = connection;
this.DataTable = dataTable;
this.DataAdapter = new MySqlDataAdapter(
string.Format( "SELECT * FROM {0} WHERE 1=0",
this.DataTable.TableName ), this.Connection );
this.DataAdapter.UpdateBatchSize = 50;
// Using workaround for MySQL Connector bug described at:
// http://bugs.mysql.com/bug.php?id=39815
// Dispose the builder before setting adapter commands.
MySqlCommandBuilder builder = new MySqlCommandBuilder( this.DataAdapter );
MySqlCommand updateCommand = builder.GetUpdateCommand();
MySqlCommand insertCommand = builder.GetInsertCommand();
MySqlCommand deleteCommand = builder.GetDeleteCommand();
builder.Dispose();
this.DataAdapter.UpdateCommand = updateCommand;
this.DataAdapter.InsertCommand = insertCommand;
this.DataAdapter.DeleteCommand = deleteCommand;
this.DataAdapter.RowUpdating += new MySqlRowUpdatingEventHandler( DataAdapter_RowUpdating );
this.DataAdapter.RowUpdated += this.OnRowUpdated;
// Create a command to fetch the last inserted id
identityCommand = this.Connection.CreateCommand();
identityCommand.CommandText = "SELECT LAST_INSERT_ID()";
this.RefreshIdentitySeed();
}
开发者ID:tkrehbiel,项目名称:UvMoney,代码行数:32,代码来源:MySqlTableContext.cs
示例2: Bind
public void Bind()
{
mySqlConnection = new MySqlConnection(
"SERVER=localhost;" +
"DATABASE=baza;" +
"UID=root;");
mySqlConnection.Open();
string query = "SELECT * FROM cennik";
mySqlDataAdapter = new MySqlDataAdapter(query, mySqlConnection);
mySqlCommandBuilder = new MySqlCommandBuilder(mySqlDataAdapter);
mySqlDataAdapter.UpdateCommand = mySqlCommandBuilder.GetUpdateCommand();
mySqlDataAdapter.DeleteCommand = mySqlCommandBuilder.GetDeleteCommand();
mySqlDataAdapter.InsertCommand = mySqlCommandBuilder.GetInsertCommand();
dataTable = new DataTable();
mySqlDataAdapter.Fill(dataTable);
bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
dataGridView3.DataSource = bindingSource;
}
开发者ID:BGCX261,项目名称:zpi-serwis-motocyklowy-svn-to-git,代码行数:25,代码来源:Form2.cs
示例3: SqlDataTable
public DataTable SqlDataTable(string strname, string str, out DataSet ds, out MySqlDataAdapter da)
{
try
{
conn.Open();
da = new MySqlDataAdapter(str, connstr);
MySqlCommandBuilder thisBuilder = new MySqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, strname);
DataTable mytable = new DataTable();
mytable = ds.Tables[0];
return mytable;
}
catch (Exception ex)
{
da = null;
ds = null;
System.Windows.Forms.MessageBox.Show(ex.Message);
return null;
}
finally
{
conn.Close();
}
}
开发者ID:zhaoziy,项目名称:Project_Li,代码行数:25,代码来源:DatabaseCmd.cs
示例4: getCommand
public static DataTable getCommand()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
try
{
// Ouverture de la connexion
M_Connexion.Gestion.Open();
// Requête SQL
String ReqSQL = "SELECT * FROM commande WHERE status = ?";
MySqlDataAdapter da = new MySqlDataAdapter(ReqSQL, M_Connexion.Gestion);
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
da.SelectCommand.Parameters.AddWithValue("@status", "En cours");
da.Fill(ds, "commande");
dt = ds.Tables[0];
// Fermeture de la connexion
M_Connexion.Gestion.Close();
}
catch (Exception ex)
{
MessageBox.Show("Erreur :" + ex.Message);
M_Connexion.Gestion.Close();
}
return dt;
}
开发者ID:Mansikkapoika,项目名称:Musichall-Logiciel,代码行数:29,代码来源:M_Commande.cs
示例5: LoadMySql
public void LoadMySql(string serverName,// Адрес сервера (для локальной базы пишите "localhost")
string userName, // Имя пользователя
string dbName,//Имя базы данных
int port, // Порт для подключения
string password,
string _table)
{
string connStr;
string strTable;
DataTable table;
connStr = "Database="+dbName+";Data Source=" + serverName + ";User Id=" + userName + ";Password=" + password;
conn = new MySqlConnection(connStr);
strTable = _table;
string sql = "SELECT * FROM " + strTable; // Строка запроса
conn.Open();
MyData = new MySqlDataAdapter(sql,conn);
MySqlCommandBuilder builder = new MySqlCommandBuilder(MyData);
MyData.InsertCommand = builder.GetInsertCommand();
MyData.UpdateCommand = builder.GetUpdateCommand();
MyData.DeleteCommand = builder.GetDeleteCommand();
table = new DataTable();
MyData.Fill(table);
UpdateGrid(table);
}
开发者ID:javavirys,项目名称:MySQLEditor,代码行数:26,代码来源:Form1.cs
示例6: getCategoriesTab
public static DataTable getCategoriesTab()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
try
{
// Ouverture de la connexion
M_Connexion.Gestion.Open();
// Requête SQL
String ReqSQL = "SELECT * FROM categorie";
MySqlDataAdapter da = new MySqlDataAdapter(ReqSQL, M_Connexion.Gestion);
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
da.Fill(ds, "categorie");
dt = ds.Tables[0];
// Fermeture de la connexion
M_Connexion.Gestion.Close();
}
catch (Exception ex)
{
MessageBox.Show("Erreur :" + ex.Message);
}
return dt;
}
开发者ID:Mansikkapoika,项目名称:Musichall-Logiciel,代码行数:26,代码来源:M_Categories.cs
示例7: SaveFromCache
internal static void SaveFromCache(string strTableName)
{
try
{
// Creates the data adapter and sets it with the update commands
MySqlDataAdapter daAdapter = GetAdapter(strTableName);
MySqlCommandBuilder cbBuilder = new MySqlCommandBuilder(daAdapter);
// Updating table as is
int nRowsUpdated = daAdapter.Update(Cache.SDB.Tables[strTableName]);
Globals.LogFiles["DataBaseLog"].AddMessages(Globals.DbActivity.WRITE.ToString() +
" at " + DateTime.Now,
"Command: Adapter.Update(" + strTableName + ")",
"Result: " + nRowsUpdated.ToString());
}
// In the event of a databse exception
catch (MySqlException e)
{
Globals.LogFiles["ErrorLog"].AddError(e.ErrorCode, e.Message, DateTime.Now);
Globals.LogFiles["ErrorLog"].AddMessage(e.StackTrace);
}
// If any other exception occurs
catch (Exception e)
{
Globals.LogFiles["ErrorLog"].AddError(Globals.ErrorCodes.SQL_ERROR, e.Message, DateTime.Now);
Globals.LogFiles["ErrorLog"].AddMessages(e.StackTrace, e.InnerException.Message);
}
}
开发者ID:smwentum,项目名称:MyHome,代码行数:30,代码来源:GlobalDataAccess.cs
示例8: button10_Click
//meat and soft drinks
private void button10_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
if (tablecheck == 2)
{
//meat
try
{
string myConnection = conection;
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
//myDataAdapter.SelectCommand = new MySqlCommand("select Table_ID from demo.table where Table_Status = 'Available' and Seat_Numbers = '" + searchValue.ToString() + "'", myConn);
MySqlCommand comand = new MySqlCommand("select * from demo.menu_item where Item_Type = 'Meat + Fish' ;", myConn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
myConn.Open();
MySqlDataReader reader = comand.ExecuteReader();
while (reader.Read())
{
listBox1.Items.Add(reader.GetString(1));
listBox1.Items.Add(reader.GetString(2));
listBox1.Items.Add(reader.GetString(6));
}
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else if (tablecheck == 4)
{
//soft drinks
try
{
string myConnection = conection;
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
//myDataAdapter.SelectCommand = new MySqlCommand("select Table_ID from demo.table where Table_Status = 'Available' and Seat_Numbers = '" + searchValue.ToString() + "'", myConn);
MySqlCommand comand = new MySqlCommand("select * from demo.menu_item where Item_Type = 'Soft Drinks' ;", myConn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
myConn.Open();
MySqlDataReader reader = comand.ExecuteReader();
while (reader.Read())
{
listBox1.Items.Add(reader.GetString(1));
listBox1.Items.Add(reader.GetString(2));
listBox1.Items.Add(reader.GetString(6));
}
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
开发者ID:Dan-Williams93,项目名称:Automated-Restaurant-System,代码行数:61,代码来源:Form1.cs
示例9: AutoIncrementColumns
public void AutoIncrementColumns()
{
execSQL("DROP TABLE IF EXISTS Test");
execSQL("CREATE TABLE Test (id int(10) unsigned NOT NULL auto_increment primary key)");
execSQL("INSERT INTO Test VALUES(NULL)");
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
Assert.AreEqual(1, ds.Tables[0].Rows[0]["id"]);
DataRow row = ds.Tables[0].NewRow();
ds.Tables[0].Rows.Add(row);
try
{
da.Update(ds);
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
ds.Clear();
da.Fill(ds);
Assert.AreEqual(1, ds.Tables[0].Rows[0]["id"]);
Assert.AreEqual(2, ds.Tables[0].Rows[1]["id"]);
cb.Dispose();
}
开发者ID:rykr,项目名称:connector-net,代码行数:29,代码来源:DataAdapterTests.cs
示例10: consultar
//Consultas a la Base de Datos (Poder llenar el DataGridView)
public void consultar(string sql, string tabla)
{
ds.Tables.Clear();
da = new MySqlDataAdapter(sql, con);
cmb = new MySqlCommandBuilder(da);
da.Fill(ds, tabla);
}
开发者ID:jesusfsg06,项目名称:Proyecto-de-Dios,代码行数:8,代码来源:crud.cs
示例11: UpdateData
public void UpdateData(string tableName, string tableColumn, int limit, Action<DataRow> action)
{
var dataSet = new DataSet();
using (var connection = new MySqlConnection(GetConnectionString()))
{
connection.Open();
var q = string.Format(Query, tableName, tableColumn, limit);
var adapter = new MySqlDataAdapter
{
SelectCommand = new MySqlCommand(q, connection) { CommandTimeout = 300 },
};
var builder = new MySqlCommandBuilder(adapter);
adapter.Fill(dataSet);
// Code to modify data in the DataSet here.
foreach (DataRow row in dataSet.Tables[0].Rows)
{
action(row);
}
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.Update(dataSet);
}
}
开发者ID:mkaczynski,项目名称:Passim,代码行数:26,代码来源:DataHelper.cs
示例12: GetData
private void GetData(string selectCommand)
{
try
{
// Specify a connection string. Replace the given value with a
// valid connection string for a Northwind SQL Server sample
// database accessible to your system.
String connectionString = "server=localhost;uid=root;pwd=root;database=esalon;";
// Create a new data adapter based on the specified query.
dataAdapter = new MySqlDataAdapter(selectCommand, connectionString);
// Create a command builder to generate SQL update, insert, and
// delete commands based on selectCommand. These are used to
// update the database.
MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder(dataAdapter);
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
}
catch (MySqlException)
{
MessageBox.Show("Unable to connect to the database. Please check your connection string");
}
}
开发者ID:DirkViljoen,项目名称:eSalon,代码行数:28,代码来源:Lookups.cs
示例13: 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);
MySqlCommand _Command = (MySqlCommand)CreateCommand(_sCmdText, CommandType.Text);
MySqlDataAdapter _adapter = new MySqlDataAdapter(_Command);
MySqlDataAdapter _adapter1 = new MySqlDataAdapter(_Command);
MySqlCommandBuilder _builder = new MySqlCommandBuilder(_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, ",@" + _dc.ColumnName);
_adapter.InsertCommand.Parameters.Add("@" + _dc.ColumnName, MySqlDbType.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;
}
开发者ID:bluedusk,项目名称:DBHelper,代码行数:64,代码来源:MySqlHelper.cs
示例14: RetDataTable
public DataTable RetDataTable(string sql)
{
data = new DataTable();
da = new MySqlDataAdapter(sql, conn);
cb = new MySqlCommandBuilder(da);
da.Fill(data);
return data;
}
开发者ID:danilomeneghel,项目名称:prova_aspnet,代码行数:9,代码来源:AcessoBancoDados.cs
示例15: SaveNewItems
public int SaveNewItems(ref DataTable NewItemTBL)
{
command = new MySqlCommand(SQL_SELECT_ITEM, GetDBConnection());
adapter = new MySqlDataAdapter();
adapter.SelectCommand = command;
builder = new MySqlCommandBuilder(adapter);
adapter.InsertCommand = builder.GetInsertCommand();
adapter.ContinueUpdateOnError = true;
return adapter.Update(NewItemTBL);
}
开发者ID:RalphC,项目名称:wahdvlib,代码行数:10,代码来源:dal.cs
示例16: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//Sets the environment to run an Sql command with the DataAdapter
MySqlCommandBuilder cmb = new MySqlCommandBuilder(da);
//Update command that actually updates the value in the DB with what was inputted in the grid(Only count can be altered)
da.Update(ds, sTable);
//Show successful completion and close the form
MessageBox.Show("Table Updated\n\nThis form will now close");
this.Close();
}
开发者ID:vercellottic03,项目名称:Capstone,代码行数:10,代码来源:ViewInventory.cs
示例17: frmrfid_Load
private void frmrfid_Load(object sender, EventArgs e)
{
string strConn = "server=localhost;user id=root;database=pharma;password=;";
ad = new MySqlDataAdapter("select * from `rfid`", strConn);
MySqlCommandBuilder builder = new MySqlCommandBuilder(ad);
ad.Fill(this.newDataSet.rfid);
ad.DeleteCommand = builder.GetDeleteCommand();
ad.UpdateCommand = builder.GetUpdateCommand();
ad.InsertCommand = builder.GetInsertCommand();
MySqlDataAdapter ad3;
}
开发者ID:votrongdao,项目名称:PEIMS,代码行数:11,代码来源:frmRfid.cs
示例18: commitChanges
public void commitChanges(String query, DataTable dataTable)
{
lock (syncLock)
{
var adapter = new MySqlDataAdapter();
var mcb = new MySqlCommandBuilder(adapter);
adapter.SelectCommand = new MySqlCommand(query, conn);
adapter.Update(dataTable);
dataTable.AcceptChanges();
}
}
开发者ID:BlackWolfsDen,项目名称:Spell-Editor-GUI-V2,代码行数:11,代码来源:MySQL.cs
示例19: btn_add_car_save_Click
private void btn_add_car_save_Click(object sender, EventArgs e)
{
try
{
f_car_ID = Int32.Parse(tb_CarID.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
return;
}
f_year = tb_Year.Text;
f_maker = tb_Maker.Text;
f_model = tb_Model.Text;
f_color = tb_color.Text;
f_trim = tb_Trim.Text;
try
{
f_MSRP = Int32.Parse(tb_MSRP.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
myConn = new MySqlConnection(connStr);
MySqlCommand myComm = myConn.CreateCommand();
MySqlDataReader Reader;
myComm.CommandText = "INSERT INTO `khnz786`.`Inventory` (`Car_ID`, `Maker`, `Model`, `Trim`, `Color`, `Engine`, `MSRP`)" +
"VALUES ("+ f_car_ID +", '"+f_maker+"', '"+f_model+"', '"+f_trim+"', '"+f_color+"', '"+f_year+"', '"+f_MSRP+"');";
myConn.Open();
MySQLDA = new MySqlDataAdapter(myComm.CommandText, myConn);
MySQLCB = new MySqlCommandBuilder(MySQLDA);
dt = new DataTable();
try
{
MySQLDA.Fill(dt);
MessageBox.Show("Car added successfully!");
Clear();
this.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
BS = new BindingSource();
BS.DataSource = dt;
}
开发者ID:pragi,项目名称:EMS_CarDealership,代码行数:51,代码来源:Car_Details.cs
示例20: btnSearch_Click
private void btnSearch_Click(object sender, EventArgs e)
{
String search_value;
String column_value = "";
int caseswitch = 0;
caseswitch = ddlSearch_Column.SelectedIndex;
switch (caseswitch)
{
case 0:
column_value = "Last_Name";
break;
case 1:
column_value = "Phone";
break;
case 2:
column_value = "Customer_ID";
break;
}
search_value = tb_Search.Text;
string connStr = "SERVER=www.freesql.org;DATABASE=khnz786;UID=khnz786;PASSWORD=ziakhan";
MySqlConnection myConn = new MySqlConnection(connStr);
MySqlCommand myComm = myConn.CreateCommand();
MySqlDataReader Reader;
if (search_value == "")
{
MessageBox.Show("Please enter a value into the search box.");
return;
}
else
{
myComm.CommandText = "SELECT * FROM Customers WHERE " + column_value + "= '" + search_value + "'";
}
myConn.Open();
MySqlDataAdapter MySQLDA = new MySqlDataAdapter(myComm.CommandText, myConn);
MySqlCommandBuilder MySQLCB = new MySqlCommandBuilder(MySQLDA);
DataTable dt = new DataTable();
MySQLDA.Fill(dt);
BindingSource BS = new BindingSource();
BS.DataSource = dt;
dg_Search.DataSource = BS;
Reader = myComm.ExecuteReader();
//while (Reader.Read())
//{
// MessageBox.Show(column_value);
//}
myConn.Close();
}
开发者ID:pragi,项目名称:EMS_CarDealership,代码行数:51,代码来源:Form1.cs
注:本文中的MySql.Data.MySqlClient.MySqlCommandBuilder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论