各位大哥,小弟新手,学习C#数据库插入时,用Access无法将数据插入,程式不报错。
代码如下:
namespace TestAdd
{
public partial class Form1 : Form
{
private static string strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\Data.MDB";
private OleDbConnection conConnection = new OleDbConnection(strConnect);
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
conConnection.Open();
this.conConnection.Open();
string strCommand = "insert into TestMdb(Textword)values('" + textBox1.Text + "')";
OleDbCommand cmd = new OleDbCommand(strCommand, conConnection);
cmd.ExecuteNonQuery();
this.conConnection.Close();
}
}
}数据库中有2个字段,一个是Id,自动增长,一个是Textword,文本型。试了网上说的权限问题,也检查了数据设计,都解决不了。求知道的大哥大姐们帮忙看一下。谢谢!
代码如下:
namespace TestAdd
{
public partial class Form1 : Form
{
private static string strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\Data.MDB";
private OleDbConnection conConnection = new OleDbConnection(strConnect);
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
conConnection.Open();
this.conConnection.Open();
string strCommand = "insert into TestMdb(Textword)values('" + textBox1.Text + "')";
OleDbCommand cmd = new OleDbCommand(strCommand, conConnection);
cmd.ExecuteNonQuery();
this.conConnection.Close();
}
}
}数据库中有2个字段,一个是Id,自动增长,一个是Textword,文本型。试了网上说的权限问题,也检查了数据设计,都解决不了。求知道的大哥大姐们帮忙看一下。谢谢!
那请问一下,在调试的时候是否能够添加到根目录下面的数据库中么?
if(ok>0)
{
message.show(“成功”);
}
else
{
message.show(“失败”);
}