C# Can';t添加DLL引用?(后续)

C# Can';t添加DLL引用?(后续),c#,dll,dsn,C#,Dll,Dsn,后续行动 我也读过其他一些问题,但不明白是什么导致了这种情况的发生。权限?如何应用工作环境?什么是跛脚的 我被引导到教程中,并将其应用到一个C#程序中,在点击按钮时执行 然而,我在这一行得到一个错误 [DllImport("ODBCCP32.dll")] 陈述 The type or namespace name "DllImport" could not be found (are you missing a using directory or an assembly reference?

后续行动 我也读过其他一些问题,但不明白是什么导致了这种情况的发生。权限?如何应用工作环境?什么是跛脚的

我被引导到教程中,并将其应用到一个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
}
}

似乎我只是把一些事情弄糊涂了。 我可以将.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();
}   
}

顺便说一句,在标签中有C意味着你不需要在标题中有“(C”)。你的链接()与此有什么关系?哎呀,我打开了很多窗口