当我单击“保存”时输入数据时,我无法在MS Access上访问我的数据库,MsgBox显示无法找到文件路径目录。你知道我做错了什么,为什么我的DB没有按预期连接?
public partial class signup : Form
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= amsid.accdb");
OleDbDataAdapter ad = new OleDbDataAdapter();
public signup()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
ad.InsertCommand = new OleDbCommand("insert into Signup values(@Username,@Password,@Email,@Admin_Code)", con);
ad.InsertCommand.Parameters.Add("@Username", OleDbType.VarChar).Value = username.Text.ToString();
ad.InsertCommand.Parameters.Add("@Password", OleDbType.VarChar).Value = password.Text.ToString();
ad.InsertCommand.Parameters.Add("@Email", OleDbType.VarChar).Value = email.Text.ToString();
ad.InsertCommand.Parameters.Add("@Admin_Code", OleDbType.VarChar).Value = admincode.Text.ToString();
con.Open();
ad.InsertCommand.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
答案 0 :(得分:0)
明确说明.accdb
文件的路径,它应该可以解决您的问题。