C#连接Access数据库无法插入数据
尝试插入Access数据库中数据,ExecuteNonQuery()返回值显示已经成功,但是检查数据库仍然没有刚才插入的数据,代码如下: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.Configuration;
using System.Data.OleDb;
namespace AccessDataTest
{
public partial class insert : Form
{
public insert()
{
InitializeComponent();
}
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["AccessDataTestConnection"].ConnectionString);
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
if(conn.State==ConnectionState.Open)
{
MessageBox.Show("该数据库已经成功连接!");
}
conn.Close();
}
private void button2_Click(object sender, EventArgs e)
{
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
String h = Theight.Text + "cm";
String w = TWeight.Text + "kg";
String InsertStr = "insert into 演员(姓名,性别,年龄,身高,体重,出生日期,主要领域) "+"values('"+TName.Text+"','"+TSex.Text+"',"+TAge.Text+",'"+h+"','"+w+"','"+TBirth.Text+"','"+TMainCa.Text+"')";
//textBox1.Text = InsertStr;
//MessageBox.Show(InsertStr);
= InsertStr;
int i=cmd.ExecuteNonQuery();
if(i>0)
{
MessageBox.Show("成功输入数据!");
}
conn.Close();
}
}
}