本文整理汇总了C#中MySql.Data.MySqlClient.MySqlCommand类的典型用法代码示例。如果您正苦于以下问题:C# MySql.Data.MySqlClient.MySqlCommand类的具体用法?C# MySql.Data.MySqlClient.MySqlCommand怎么用?C# MySql.Data.MySqlClient.MySqlCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MySql.Data.MySqlClient.MySqlCommand类属于命名空间,在下文中一共展示了MySql.Data.MySqlClient.MySqlCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditSptInfo
private void EditSptInfo(SettingsData returnEditedsettingsData)
{
MySql.Data.MySqlClient.MySqlConnection msqlConnection = null;
msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password=technicise;database=sptdb;persist security info=False");
try
{ //define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
msqlCommand.Connection = msqlConnection;
msqlConnection.Open();
int idSptinfo = 1;
msqlCommand.CommandText = "UPDATE sptinfo SET name='" + returnEditedsettingsData.Name + "', address='" + returnEditedsettingsData.Address + "', phone='" +
returnEditedsettingsData.Phone + "', bill_disclaimer='" + returnEditedsettingsData.BillDisclaimer + "', invoice_prefix='" + returnEditedsettingsData.InvoicePrefix +
"' WHERE id_sptinfo='" + idSptinfo + "'; ";
msqlCommand.ExecuteNonQuery();
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
finally
{
//always close the connection
msqlConnection.Close();
}
}
示例2: FetchePassword
public static string FetchePassword()
{
string passwordStr = string.Empty;
MySql.Data.MySqlClient.MySqlConnection msqlConnection = null;
msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password=technicise;database=sptdb;persist security info=False");
try
{ //define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
msqlCommand.Connection = msqlConnection;
msqlConnection.Open();
msqlCommand.CommandText = "Select password from sptinfo;";
MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();
msqlReader.Read();
passwordStr = msqlReader.GetString("password");
}
catch (Exception er)
{
//Assert//.Show(er.Message);
}
finally
{
//always close the connection
msqlConnection.Close();
}
return passwordStr;
}
示例3: SqlScalar
/// <summary>
/// Для выполнения запросов к MySQL с возвращением 1 параметра.
/// </summary>
/// <param name="sql">Текст запроса к базе данных</param>
/// <param name="connection">Строка подключения к базе данных</param>
/// <returns>Возвращает значение при успешном выполнении запроса, текст ошибки - при ошибке.</returns>
public static MyResult SqlScalar(string sql, string connection)
{
MyResult result = new MyResult();
try
{
MySql.Data.MySqlClient.MySqlConnection connRC = new MySql.Data.MySqlClient.MySqlConnection(connection);
MySql.Data.MySqlClient.MySqlCommand commRC = new MySql.Data.MySqlClient.MySqlCommand(sql, connRC);
connRC.Open();
try
{
result.ResultText = commRC.ExecuteScalar().ToString();
result.HasError = false;
}
catch (Exception ex)
{
result.ErrorText = ex.Message;
result.HasError = true;
}
connRC.Close();
}
catch (Exception ex)//Этот эксепшн на случай отсутствия соединения с сервером.
{
result.ErrorText = ex.Message;
result.HasError = true;
}
return result;
}
示例4: assignEstimator
public static void assignEstimator(estimateInfo estimateToEdit)
{
MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();
try
{ //define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
msqlCommand.Connection = msqlConnection;
msqlCommand.CommandText = "UPDATE estimate SET [email protected] WHERE [email protected]";
msqlCommand.Parameters.AddWithValue("@estimator", estimateToEdit.estimator);
msqlCommand.Parameters.AddWithValue("@appNo", estimateToEdit.appsNo);
msqlCommand.ExecuteNonQuery();
}
catch (Exception er)
{
}
finally
{
//always close the connection
msqlConnection.Close();
}
}
示例5: ConnectInsertToDoListTable
public static void ConnectInsertToDoListTable(ToDoData tdData)
{
//define the connection reference and initialize it
MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();
try
{ //define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
msqlCommand.Connection = msqlConnection;
msqlCommand.CommandText = "INSERT INTO to_do(date_time,to_do,id)" + "VALUES(@date_time,@to_do,@id)";
msqlCommand.Parameters.AddWithValue("@date_time", tdData.date_time);
msqlCommand.Parameters.AddWithValue("@to_do", tdData.to_do);
msqlCommand.Parameters.AddWithValue("@id", tdData.id);
msqlCommand.ExecuteNonQuery();
}
catch (Exception er)
{
}
finally
{
//always close the connection
msqlConnection.Close();
}
}
示例6: assignDonor
public static void assignDonor(PatientInfo patientData)
{
MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();
try
{ //define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
msqlCommand.Connection = msqlConnection;
msqlCommand.CommandText = "UPDATE patient SET [email protected]_donor, assigned_donor_contact = @assigned_donor_contact WHERE [email protected]_id";
msqlCommand.Parameters.AddWithValue("@patient_id", patientData.id);
msqlCommand.Parameters.AddWithValue("@assigned_donor", patientData.assignedDonor);
msqlCommand.Parameters.AddWithValue("@assigned_donor_contact", patientData.donorContact);
msqlCommand.ExecuteNonQuery();
}
catch (Exception er)
{
}
finally
{
//always close the connection
msqlConnection.Close();
}
}
示例7: StateChanged_Executed
void StateChanged_Executed(object sender, ExecutedEventArgs e)
{
string messgae = "불러오기를 완료하였습니다.";
AMR_MST04Model model = new AMR_MST04Model();
model = (AMR_MST04Model)e.Parameter;
MySqlManage crud = new MySqlManage(ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString);
DataSet ds = new DataSet();
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.CommandText = "CALL sp_load(@sno, @datefrom, @dateto);";
cmd.Parameters.AddWithValue("@sno", model.MST04SNO);
cmd.Parameters.AddWithValue("@datefrom", model.From.ToString("yyyy-MM-dd") + " 00");
cmd.Parameters.AddWithValue("@dateto", model.To.ToString("yyyy-MM-dd") + " 00");
ds = crud.CallSPMariaDBTable(crud.Connection, cmd);
if (ds.Tables.Count > 0)
{
model.DataTable = ds.Tables[0];
CurrentForm.SearchComplete(model);
}
CurrentForm.ShowMessage(messgae);
}
示例8: Register_AfterCheck
public bool Register_AfterCheck(string Username, string Password, string Email, string FullName)
{
MySql.Data.MySqlClient.MySqlConnection con = null;
Database.Configuration.open(ref con);
string sql = @"
INSERT INTO `users`(`level`, `state`, `username`, `email`, `password`, `realname`)
VALUES (@level, @state, @username, @email, @password, @realname)";
var defaultLevel = Util.Config.Get().GetInt32("registration_default_authlevel", 2);
var defaultState = Util.Config.Get().GetInt32("registration_default_state", 0);
using (var rdr = new MySql.Data.MySqlClient.MySqlCommand(sql, con)) {
rdr.Parameters.AddWithValue("@level", defaultLevel);
rdr.Parameters.AddWithValue("@state", defaultState);
rdr.Parameters.AddWithValue("@username", Username);
rdr.Parameters.AddWithValue("@realname", FullName);
rdr.Parameters.AddWithValue("@email", Email);
rdr.Parameters.AddWithValue("@password", Password);
try {
rdr.ExecuteNonQuery(); // Let it throw a error so i can see if it works
} catch(Exception ex) {
throw;
return false;
}
} con.Close();
return true;
}
示例9: GetForecastFromDatabase
public CityForeCast[] GetForecastFromDatabase()
{
//SqlConnection connection = new SqlConnection(@"Data Source=(LocalDb)\MSSQLLocalDb;Initial Catalog=weatherForecast;Integrated Security=True;Pooling=False");
MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(@"Server=eu-cdbr-azure-west-c.cloudapp.net;Database=BDMeteo;Uid=b95badd8e1dbad;Pwd=bde4c7b6;Pooling=True");
connection.Open();
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM tablemeteo", connection);
MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader();
List<CityForeCast> forecasts = new List<CityForeCast>();
while (reader.Read())
{
CityForeCast forecast = new CityForeCast();
forecast.City = (string)reader["City"];
forecast.description = (string)reader["Description"];
forecast.MaxTemp = (decimal)reader["Temperature"];
forecasts.Add(forecast);
}
reader.Close(); // Fermer le reader avant de fermer la connection
connection.Close();
return forecasts.ToArray();
//var ctx = new weatherForecastEntities();
//var forecast = ctx.Tables.Select(f => new CityForeCast()
//{
// City = f.City,
// description = f.Description,
// MaxTemp = (decimal)f.Temperature
//});
//return forecast;
}
示例10: DeleteStock
private void DeleteStock(string stockToDelete)
{
msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password=technicise;database=sptdb;persist security info=False");
try
{ //define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
msqlCommand.Connection = msqlConnection;
msqlConnection.Open();
msqlCommand.CommandText = "DELETE FROM stock WHERE id= @vendorIdToDelete";
msqlCommand.Parameters.AddWithValue("@vendorIdToDelete", stockToDelete);
MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
finally
{
//always close the connection
msqlConnection.Close();
}
}
示例11: ConnectInsertTocustomerPaymentTable
public static void ConnectInsertTocustomerPaymentTable(CustomerPaymentData customerDataObject)
{
MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();
try
{
//define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
//define the connection used by the command object
msqlCommand.Connection = msqlConnection;
FeedcustomerData(msqlCommand, customerDataObject);
}
catch (Exception er)
{
}
finally
{
msqlConnection.Close();
}
}
示例12: EditSptPassword
public static void EditSptPassword(string passwordStr)
{
MySql.Data.MySqlClient.MySqlConnection msqlConnection = null;
msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password=technicise;database=sptdb;persist security info=False");
try
{ //define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
msqlCommand.Connection = msqlConnection;
msqlConnection.Open();
int idSptinfo = 1;
msqlCommand.CommandText = "UPDATE sptinfo SET password='" + passwordStr + "' WHERE id_sptinfo='" + idSptinfo + "'; ";
msqlCommand.ExecuteNonQuery();
}
catch (Exception er)
{
//MessageBox.Show(er.Message);
}
finally
{
//always close the connection
msqlConnection.Close();
}
}
示例13: AddAgent
public bool AddAgent(string name, string surname, string phone, string email, string password)
{
DatabaseManager dbManager = new DatabaseManager();
Cryptography crypto = new Cryptography();
MySql.Data.MySqlClient.MySqlCommand com = new MySql.Data.MySqlClient.MySqlCommand();
return (dbManager.NonReturnQuery("INSERT INTO Agent (Agent_Name , Agent_Surname, Agent_Phone, Agent_Email, Agent_Password) VALUES ('" + name + "','" + surname + "','" + phone + "','" + email + "','" + Cryptography.CreateHash(password).ToString() + "');"));
}
示例14: buttonOK_Click
private void buttonOK_Click(object sender, EventArgs e)
{
var conn = this.dataset.CreateSQLConnection();
conn.Open();
var query = new MySql.Data.MySqlClient.MySqlCommand(String.Format("call settlement('{0}')",dateTimePickerSettleDate.Value.ToString("yyyy-MM-dd")), conn);
query.ExecuteNonQuery();
this.Close();
}
示例15: Execute
public static int Execute(string sql)
{
using (var conn = new MySql.Data.MySqlClient.MySqlConnection(ConnectString()))
{
conn.Open();
var cmd = new MySql.Data.MySqlClient.MySqlCommand(sql, conn);
int i = cmd.ExecuteNonQuery();
conn.Close();
return i;
}
}