으로 변환이 스크립트를 C#으로 변환하는 데 도움이 될 수 있습니까? 저는 여전히 C#에서 많은 초보자 및 학습자입니다. 이 스크립트는 OpenCurrentDatabase를 사용하여 Access .mdb 파일을 열고 엽니 다.이 메서드와 코드를 그대로 사용해야하지만 C#으로 변환하면 도움이 될 것입니다.VBScript를 C#
저는 cs 파일을 편집하기 위해 메모장을 사용하고 csc.exe를 컴파일하여 (다른 C# 도구가 없습니다) 사용하고 있습니다.
// Declare the path to the database file
var filePath = @"Path\to\database.accdb";
// If statement using File.Exists()
if (File.Exists(filePath))
{
// Create new OleDbConnection object and call Open()
var conn = new OleDbConnection($"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={filePath}");
conn.Open();
}
else
{
// Write to the console if the file does not exist
Console.WriteLine("The file does not exist");
}
당신은 것입니다 : 당신이 당신의 VBScript를 어딘가에 저장 한 경우 그냥 데이터베이스에 대한 연결을 열 필요가있는 경우
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
dim filePath
filePath = fso.GetParentFolderName(WScript.ScriptFullName)
filePath = filePath & "\test.mdb"
'WScript.Echo filePath
If (fso.FileExists(filePath)) Then
dim appAccess
set appAccess = createObject("Access.Application")
appAccess.visible = true
appAccess.UserControl = true 'To leave the application open after the script completes you need to set the UserControl property to true.
appAccess.OpenCurrentDatabase filePath, True, "mypassword"
Else
WScript.Echo "File doesn’t exist"
End If
사용자가 수동으로 액세스 할 수 있도록 데이터베이스를 열어야합니까, 아니면 프로그래밍 적으로 (C#을 사용하여) 삽입/쿼리 할 것입니까? – Bassie