2
The error says:- The ConnectionString Property has not been initialized at system.data.OledbOledConnection.PermissionDemand().
我無法找出錯誤。有人可以解釋它是什麼意思以及如何解決它?
C#代碼:
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.OleDb;//microsoft database
namespace AccessLoginApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\admin\Documents\Book Database.accdb;
Persist Security Info=False;";
}
catch (Exception ex)
{
MessageBox.Show("Error"+ ex);
}
}
private void button1_Click(object sender, EventArgs e)
{
try{
OleDbConnection connection = new OleDbConnection();
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = " Insert into Book Name(Book Name,Book Number,Publisher) values('" + bookName.Text + "','" + bookNumber.Text + "','" + publisher.Text + "')";
command.ExecuteNonQuery();
MessageBox.Show("Data Saved");
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}
}
}
標識符預期,int是關鍵字。如何使用它? – YoMama
@YoMama:它改變爲'Integer' –
感謝您的幫助,但是,它仍然給我error..Error.System.Data.OledbException(0x80040e14):在INSERT INTO語句的語法錯誤。 – YoMama