C# 在textbox中编写数据添加到dategridview中(access数据库)
添加几个textbox,在每个textbox中输入相关数据,单击button3就能将整行数据添加到dategridview中,请问该如何编写button3?usingSy...
添加几个textbox,在每个textbox中输入相关数据,单击button3就能将整行数据添加到dategridview中,请问该如何编写button3?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
namespace WindowsApplication12
{
public partial class Form1 : Form
{
private DataSet dsmain = new DataSet();
private OleDbCommand command = new OleDbCommand();
private DataTable thetable = new DataTable();
private OleDbDataAdapter adapter = new OleDbDataAdapter();
public Form1()
{
InitializeComponent();
this.dataGridView1.AllowUserToDeleteRows = true;
}
private void button1_Click(object sender, EventArgs e)
{
this.dataSet11.Clear();
this.oleDbDataAdapter1.Fill(dataSet11, "patient");
}
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
foreach (DataGridViewRow r in dataGridView1.SelectedRows)
{
dataGridView1.Rows.Remove(r);
}
}
}
}
} 展开
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
namespace WindowsApplication12
{
public partial class Form1 : Form
{
private DataSet dsmain = new DataSet();
private OleDbCommand command = new OleDbCommand();
private DataTable thetable = new DataTable();
private OleDbDataAdapter adapter = new OleDbDataAdapter();
public Form1()
{
InitializeComponent();
this.dataGridView1.AllowUserToDeleteRows = true;
}
private void button1_Click(object sender, EventArgs e)
{
this.dataSet11.Clear();
this.oleDbDataAdapter1.Fill(dataSet11, "patient");
}
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
foreach (DataGridViewRow r in dataGridView1.SelectedRows)
{
dataGridView1.Rows.Remove(r);
}
}
}
}
} 展开
展开全部
比如说,你有2个字段,2个textbox,一个为edit_Uid,另一个为edit_Pwd,对应的数据库字段分别为UID,PWD.
则在给这两个输入框输入值后,点击Button3,
string cmdText=string.Format("insert into patient(UID,PWD) values('{0}','{1}')",edit_Uid.Text,edit_Pwd.Text);
this.command .ExeNoneQuery(cmdText);
则在给这两个输入框输入值后,点击Button3,
string cmdText=string.Format("insert into patient(UID,PWD) values('{0}','{1}')",edit_Uid.Text,edit_Pwd.Text);
this.command .ExeNoneQuery(cmdText);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询