无法添加DLL引用?(跟进)

时间:2011-07-08 18:06:36

标签: c# dll dsn

跟进This 我还读过其他一些问题,但我不明白会导致这种情况发生的原因。权限?如何申请工作?什么是LAME?

我被引导到THIS教程并将其用于C#程序以执行Button Clicks。

但是我在这一行上收到错误

[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
}
}

1 个答案:

答案 0 :(得分: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();
}   
}
相关问题