关于连接数据库后输入并储存
我现在连接完数据库,在窗体中运行时,希望可以有输入并且将此输入存进数据库的功能。例如我希望加一行“李明 男 29岁”这条信息这是我目前的代码:
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace 试验2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection thisConnection = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\c#教程\协和医院.mdb");
string sql = "select * from Sheet1";
OleDbDataAdapter thisAdapter = new OleDbDataAdapter(sql, thisConnection);
System.Data.DataSet thisDataSet = new System.Data.DataSet();
thisAdapter.Fill(thisDataSet, "table");
DataTable dt = thisDataSet.Tables["table"];
this.dataGridView1.DataSource = dt;
thisConnection.Close();
}
}
}