标签:mode event object code view ram insert source param
帮助类:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace TestMYSQL
{
public class MySqlHelper
{
string M_str_sqlcon = string.Empty;
private MySqlHelper()
{
}
public MySqlHelper(string str_sqlcon)
{
M_str_sqlcon = str_sqlcon;
}
///
///
///
}
}
后台:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SQLToMysql_Move
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
TestMYSQL.MySqlHelper mysql = new TestMYSQL.MySqlHelper("server=127.0.0.1;user id=root;password=123456;database=ce");
private void button1_Click(object sender, EventArgs e)
{
int rel = 0;
try
{
DataSet dataset = Common.DbHelperSQL.Query("select * from dbo.Num");
DataTable dt = dataset.Tables[0];
dataGridView1.DataSource = dt;
for (int i = 0; i < dt.Rows.Count ; i++)
{
label1.Text = dt.Rows[i][0].ToString();
label2.Text = dt.Rows[i][1].ToString();
rel = mysql.getmysqlcom("INSERT INTO ce
.notice
(Content
, Start_date
, End_date
) VALUES (‘" + dt.Rows[i][1].ToString() + "‘, ‘" + dt.Rows[i][0].ToString() + "‘, ‘2‘);");
}
MessageBox.Show((rel > 0) ? "成功" : "失败");
}
catch (Exception ex)
{
throw ex;
}
//TestMYSQL.MySqlHelper mysql = new TestMYSQL.MySqlHelper("server=127.0.0.1;user id=root;password=123456;database=ce");
//string sql = "INSERT INTO ce
.notice
(Id
, Content
, Start_date
, End_date
) VALUES (‘2‘, ‘2‘, ‘2‘, ‘2‘);";
//try
//{
// int rel = mysql.getmysqlcom(sql);
// MessageBox.Show((rel > 0) ? "成功" : "失败");
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
}
}
}
相关DLL:
https://i.cnblogs.com/Files.aspx
分享一个Mysql操作方法类(MySql数据库连接、执行MySqlCommand命令、创建MySqlDataReader对象)
标签:mode event object code view ram insert source param
原文地址:https://www.cnblogs.com/75789glong/p/13909274.html