【发布时间】:2018-04-03 07:20:51
【问题描述】:
我正在尝试将值从一个表插入到另一个表中,并且不知何故我试图从 datagridview 中插入值,对此非常新手,我似乎没有正确理解它。
我的代码如下所示:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace PeaceGate
{
public partial class ScheduledAppointments : Form
{
string constring = ConfigurationManager.ConnectionStrings["myDatabaseConnection"].ConnectionString;
MySqlDataAdapter mdap;
DataSet ds;
public ScheduledAppointments()
{
InitializeComponent();
toolStripStatusLabel1.Text = "Connected as Gate";
}
private void ScheduledAppointments_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'visitor_managerDataSet1.scheduled_appointments' table. You can move, or remove it, as needed.
this.scheduled_appointmentsTableAdapter.Fill(this.visitor_managerDataSet1.scheduled_appointments);
}
private void confirmAppointmentToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
id.Text = dataGridView1.SelectedRows[0].Cells[0].Value + string.Empty;
visit_time.Text = dataGridView1.SelectedRows[0].Cells[1].Value + string.Empty;
visit_date.Text = dataGridView1.SelectedRows[0].Cells[2].Value + string.Empty;
fullname.Text = dataGridView1.SelectedRows[0].Cells[3].Value + string.Empty;
visitor_address.Text = dataGridView1.SelectedRows[0].Cells[4].Value + string.Empty;
visitor_city.Text = dataGridView1.SelectedRows[0].Cells[5].Value + string.Empty;
visitor_telephone.Text = dataGridView1.SelectedRows[0].Cells[6].Value + string.Empty;
id_method.Text = dataGridView1.SelectedRows[0].Cells[7].Value + string.Empty;
organization.Text = dataGridView1.SelectedRows[0].Cells[8].Value + string.Empty;
visit_type.Text = dataGridView1.SelectedRows[0].Cells[9].Value + string.Empty;
reason.Text = dataGridView1.SelectedRows[0].Cells[10].Value + string.Empty;
person_visit.Text = dataGridView1.SelectedRows[0].Cells[11].Value + string.Empty;
pictureBox1.Image = byteArrayToImage((byte[])dataGridView1.CurrentRow.Cells[12].Value);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
}
private Image byteArrayToImage(byte[] byteArray)
{
MemoryStream ms = new MemoryStream(byteArray);
Image img = Image.FromStream(ms);
return img;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
MySqlConnection con = new MySqlConnection(constring);
string sql = "select * from scheduled_appointments where id ='"+id.Text+"'";
mdap = new MySqlDataAdapter(sql,con);
MySqlCommandBuilder cmbl = new MySqlCommandBuilder(mdap);
mdap.Update(ds, "final_appointments");
MessageBox.Show("Appointment Confirmed!","Information",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
我正在尝试从 scheduled_appointments 获取信息并保存到 Final_appointments 中,如使用此事件处理程序的源代码所示 exitToolStripMenuItem_Click 我非常新手,请在这方面寻求指导。
【问题讨论】:
-
你有一些问题,1)你没有从“final_appointments”中读取任何数据2)你没有添加任何数据
标签: c# mysql datagridview