0

跟进这个 我还阅读了一些其他问题,但我不明白是什么导致这种情况发生。权限?如何申请变通?什么是跛脚?

我被定向到THIS教程,并将其放入 C# 程序中以在按钮单击上执行。

但是我在这条线上得到一个错误

[DllImport("ODBCCP32.dll")]

陈述

The type or namespace name "DllImport" could not be found (are you missing a using directory or an assembly reference?)

我曾尝试将该文件作为参考导入,但随后遇到此错误

"Please make sure file is accessile, and that it is a valid assembly or COM component"

我错过了我需要进口的东西吗?这是我的代码的一部分。

using System;
using System.Runtime.InteropServices;

namespace DsnUtil{
public partial class Form1 : Form{
[DllImport("ODBCCP32.dll")]
private static extern bool SQLConfigDataSource(//etc etc)
public Form1(){
   button1_Click();
}

private void button1_Click(object sender, EventArgs e){
   //DoesWork
}
}
4

1 回答 1

0

似乎我只是对一些事情感到困惑。我能够将 .dll 添加为资源而不是引用。我还分配了一个新的字符串资源作为 dll 的名称,以防我以后想使用它。

总而言之,这是有效的。

namespace DSNUtility{

public partial class Form1 : Form{
[DllImport("odbccp32.dll")]
private static extern bool SQLConfigDataSource(IntPrt parent, int request, string driver, string attribute;

public form(){
InitializeComponent();
}

//Method to handle the creation(Will be called on a Button Click)
public bool AddUserDSN(){
return SQLConfigDataSource((IntPrt)0, 1, "SQL Server",
"DSN=Testing123\0Description=Testing123\0Network=blahblah\0Trusted_Connection=No\0Server=blahblahblah\0Database=XXXXXX\0");
}

private void Form1_Load(object sender, EventArgs e){
    }

private void button1_Click(object sender, EventArgs e){
//Call the Add User Method   
AddUserDSN();
}   
}
于 2011-07-11T15:29:16.157 回答