呵呵,我来抢沙发,这个你试试,把access数据库放到debug下
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.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static OleDbConnection con = new OleDbConnection();
private static OleDbCommand cmd = new OleDbCommand();
private void button1_Click(object sender, EventArgs e)
{
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
con.ConnectionString +=System.AppDomain.CurrentDomain.BaseDirectory + @"db_user.mdb";
cmd.Connection = con;
con.Open();
cmd.CommandText = "insert into tb_user(UserName,UserPass) values('" + txtUserName.Text.Trim() + "','" + txtUserPass.Text.Trim() + "')";
cmd.ExecuteNonQuery();
}
}
}
|