表名04.04.2016
===========================
id 3
name asd
co 12
price 32
st 4
表名05.04.2016
=======================
id 3 Same
name asd Same
co <--- FROM old one ST= HERE
------------------
price 32 Same`enter code here`
st Null <--- I will write here later
表-04.04.2016是旧的
我想打开New Table还将旧表'ST'列复制到新表'CO'完全
但我需要匹配id
private void Bsayim_Click(object sender, EventArgs e)
{
MySqlCommand cmdDatabase = new MySqlCommand("CREATE TABLE IF NOT EXISTS `" + tarihbugun.Text + "` (" +
"`id` INT AUTO_INCREMENT," +
"`urun` VARCHAR(255)," +
"`gelen` VARCHAR(255)," +
"`fiyat` VARCHAR(255)," +
"`kalan` VARCHAR(255), " +
"`giden` VARCHAR(255), " +
"`maliyet` VARCHAR(255), " +
"PRIMARY KEY(id));", conn);
conn.Open();
cmdDatabase.ExecuteNonQuery();
cmdDatabase.Dispose();
conn.Close();
datagird();
if (MessageBox.Show("message", "new day", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
MySqlCommand sqlCmd1 = new MySqlCommand();
try
{
sqlCmd1.Connection = conn;
sqlCmd1.CommandType = CommandType.Text;
sqlCmd1.CommandText = "INSERT INTO `" + date.Text + "`(`id`,`product`, `pprice`) SELECT `aid`, `aproduct`, `aprice` FROM Alcol";
MySqlDataAdapter sda = new MySqlDataAdapter(sqlCmd1);
DataTable dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dataGridView1.DataSource = bSource;
sda.Update(dbdataset);
MessageBox.Show("ok","ok",MessageBoxButtons.OK,MessageBoxIcon.Information);
我用这些代码打开表05.04.2016。现在如何将'ST'从旧表复制到新表'CO'
答案 0 :(得分:0)
我发现它希望此代码可以帮助某人。
string Query = "UPDATE `11.04.2016` AS t1 INNER JOIN `10.04.2016` AS t2 ON t1.id = t2.id SET t1.xx = t2.yy";
//This is MySqlConnection here i have created the object and pass my connection string.
// MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
MySqlCommand cmd2 = new MySqlCommand(Query, conn);
MySqlDataReader MyReader2;
conn.Open();
MyReader2 = cmd2.ExecuteReader();
MessageBox.Show("Data Updated");
while (MyReader2.Read())
UPDATE Table_name
AS t1 INNER JOIN Old_table
AS t2 ON t1.id = t2.id SET t1.Columnname = t2.othercolumnname