无法在列表框中插入数据

时间:2015-06-27 16:55:59

标签: oledb feedback

我跟着this video创建了插入数据到数据库。但是,当我单击提交按钮时会出现错误消息。

这是错误消息:

Error System.Data.OleDb.OleDbException (0x80004005): 
Could not find installable ISAM. at 
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString 
constr, OleDbConnection connection) atSystem.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions 
options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, 
DbConnectionPool pool, DbConnection owningObject) at    System.Data.ProviderBase.DbConnectionFactory.CreateConnection
(DbConnectionOptions options, 
DbConnectionPoolKey poolKey, Object poolGroupProviderInfo,
 DbConnectionPool 
pool, DbConnection owningConnection, DbConnectionOptions userOptions)
 at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnect
ion owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
 at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection
(DbConnection owningConnection, TaskCompletionSource`1 retry, 
DbConnectionOptions userOptions, DbConnectionInternal oldConnection, 
DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.
TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory 
connectionFactory, TaskCompletionSource`1 retry, 
DbConnectionOptions 
userOptions) at 
System.Data.ProviderBase.DbConnectionClosed.
TryOpenConnection(DbConnection outerConnection, DbConnectionFactory 
connectionFactory, TaskCompletionSource`1 retry, 
DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionInternal.
OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 
at System.Data.OleDb.OleDbConnection.Open() 
at WebApplication4.WebForm1.Button1_Click(Object sender, EventArgs e)
 at d:\User\Downloads\WebApplication4\WebApplication4\feedback.aspx.cs: line 26 

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
    public OleDbConnection connection = new OleDbConnection(); 

    protected void Page_Load(object sender, EventArgs e)
    {

       connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\User\Downloads\WebApplication4\WebApplication4\Database.accdb;Persist Security = False; User Instance=True;";


    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try { 
        connection.Open();
        OleDbCommand command = new OleDbCommand();
        command.Connection = connection;
        command.CommandText = "insert into feedback (commentid,commentname,comment) values ('" + commentid.Text + "' , '" + IDName.Text + "' , '" + comment.Text + "')";
        command.ExecuteNonQuery();

        Label3.Text = ("Comment Submitted");

        }
        catch (Exception ex)
        {
            Label3.Text = (" Error " + ex);

        }


    }
}
}

有人可以告诉我的代码有什么问题吗?

0 个答案:

没有答案