开发者

Can't add DLL reference?(Follow up)

开发者 https://www.devze.com 2023-03-18 03:34 出处:网络
Follow up to This I have also r开发者_运维问答ead up on some other questions but am not understanding what would cause this to happen. Permissions? How to apply a work around? Whats LAME?

Follow up to This I have also r开发者_运维问答ead up on some other questions but am not understanding what would cause this to happen. Permissions? How to apply a work around? Whats LAME?

I was directed to THIS tutorial and have worked it into a C# program to execute on Button Clicks.

However I get a error on this line

[DllImport("ODBCCP32.dll")]

stating

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

I have tried inporting that file as a reference but am then hit with this error

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

Am I missing something that I need imported? Here is a section of my code.

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


It seemed that I just had some things confused. I was able to add the .dll as a Resource instead of a reference. I also assigned a new string resource as the name of the dll in case I would like to use it later.

All in all this is what worked.

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();
}   
}
0

精彩评论

暂无评论...
验证码 换一张
取 消