如何在C#中执行Access数据库功能 [英] How to execute access database funtion in C#

查看:146
本文介绍了如何在C#中执行Access数据库功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用导入规范(通过任何帮助)导入csv文件以访问数据库

我已经在Access数据库(.mdb文件)中编写了函数.

打开访问数据库-数据库工具-Visual Basic-创建了模块(Mocdle名称加载)

Importing the csv file to access database using import spec through code , any help

I have written function in access database (.mdb file)

open access database-daatabase tools-visual basic-created the module (Mocdle name Load)

Sub Import_CSV()
Dim strFile As String ''Filename
DoCmd.TransferText acImportDelimi, OPS_Import_Specs, _
    "Raw Data", strPath & strFileList(intFile), -1
End Sub



如何在c#中执行此函数,以便c#函数将返回成功或失败.

提前谢谢.

我尝试过的事情:

我已经在Access数据库中编写了该函数,但是不知道如何在c#.net



How to execute this function in c# , so that the c# function will return the success or failure.

Thanks in advance.

What I have tried:

I have written the function in access database but don''t know how to call in c#.net

推荐答案

中调用!

您必须使用c#代码创建自己的子例程.这是一个主意:如何阅读文本文件数据并使用VB.NET在datagridview中显示 [
You can''t!

You have to create own subroutine in c# code. Here is an idea: How to read text file data and display in datagridview with VB.NET[^]
Follow the links there provided.


最终解决方案.

在访问数据库创建的模块中编写以下代码.

Final working solution.

in access database created module written the below code.

tion Compare Database

Sub Import_CSV(ByVal strFile As String)
''Dim strFile As String ''Filename
DoCmd.TransferText acImportDelimi, OPS_Import_Specs, _
    "tblDetail", strFile, -1
End Sub



在C#控制台应用程序中:

添加的参考:



in c# console application :

added reference :

Microsoft.Office.Interop.Access

右键单击属性嵌入互操作类型"更改为False.

用C#编写的函数来调用Access数据库过程/function.

right-click properties "Embed Interop Types" is changed to False.

written function in c# to call access database procedure /function.

public static int RunAccessData()
       {

Microsoft.Office.Interop.Access.Application appAccess = null;
               appAccess = new Microsoft.Office.Interop.Access.ApplicationClass();
               string strFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\";
               Logger.WriteMessage("FilePath" + strFilePath);
               strFileName = WebConfig.GetSetting("InFileName");
               Logger.WriteMessage("FileName" + strFileName);
               strFilePathnName = strFilePath + strFileName;
               Logger.WriteMessage("FilePath and FileName" + strFilePathnName);
               appAccess.OpenCurrentDatabase("access database path here", false, null);
               object oMissing = System.Reflection.Missing.Value;
               object rt = appAccess.Run("Import_CSV", strFilePathnName);
               appAccess.Quit(Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveNone);



因此现在我可以调用访问方法并使用importspec成功导入数据.

谢谢您的支持.



so now I can able to call the access method and successfully import the data with importspec.

Thank you for all your support.


这篇关于如何在C#中执行Access数据库功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆