[英]Saving values from datagridview
I am new to c#. 我是C#的新手。 I have been trying to add values from my datagrid to mysql but in vain and i really need your help.
我一直在尝试将数据网格中的值添加到mysql中,但是徒劳,我真的需要您的帮助。 The values are automatically generated after a time interval of 1 sec and i need to insert them to the mysql in the same time interval.
这些值是在1秒的时间间隔后自动生成的,我需要在相同的时间间隔内将它们插入到mysql中。 Here are the codes.
这是代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
namespace BLIND_SHOPPING_SYSTEM
{
public partial class Form2 : Form
{
private DataTable m_TagDataTable = new DataTable("Tag List");
long passiveID = 0;
public Form2()
{
InitializeComponent();
this.m_TagDataTable.Columns.Add("TagID");
}
private void btn_GenerateID_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
public void timer1_Tick(object sender, EventArgs e)
{
if (passiveID < 10)
{
passiveID = passiveID + 1;
//listBox1.Items.Add(passiveID);
//this.m_TagDataTable.Columns.Add("TagID");
this.dataGridView1.DataSource = m_TagDataTable;
DataRow dr = m_TagDataTable.NewRow();
dr["TagID"] = passiveID;
m_TagDataTable.Rows.Add(dr);
}
else
// Application.Exit();
Console.ReadLine();
}
private void btn_Stop_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
}
}
Please kindly help me. 请帮助我。
您可能要使用DataTableAdapter并指定Update命令,请参见此处的一些示例;) http://msdn.microsoft.com/zh-cn/library/ms233819(v=vs.80 ) .aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.