【问题标题】:Can't add DLL reference?(Follow up)无法添加 DLL 引用?(跟进)
【发布时间】:2011-07-12 03:48:34
【问题描述】:

关注This 我还阅读了其他一些问题,但不明白会导致这种情况发生的原因。权限?如何申请变通?什么是 LAME?

我被引导到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
}
}

【问题讨论】:

  • 顺便说一句,标签中包含 C# 意味着您不需要在标题中包含“(C#)”。
  • 你的链接 (stackoverflow.com/questions/2808632/…) 和这个有什么关系?
  • 哎呀我要打开很多窗口

标签: c# dll dsn


【解决方案1】:

似乎我只是对某些事情感到困惑。 我能够将 .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-03-28
    • 1970-01-01
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-04
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多