Problème avec Excel-Dna et C#

Fermé
soufian - 9 juil. 2014 à 15:03
 soufian - 9 juil. 2014 à 15:09
Hi,
I am currently working on a program in C# which is looking for datas in a database with an excel-DNA addin. To simplify I have two columns in the SQL database, one is ID the other is Isin. I need an excel plugin in which I put he isin to get the id. (the program has other goals but my first problem is there). Please help me, I am getting crazy !
So here is my class :
public class MyFunctions
{

DBSQL B=new DBSQL(); // (here I have an object with the function get id and the connection to the server, I have this on another layer which is OK I think)


[ExcelFunction(Description = "fonction de recherche")]
public string idCL(string _isin)
//module excel
{
String res;

B.Connection();

res= "id= " + B.getID(_isin);
// (getID is in DBSQL)
B.CloseConnection();

return res;
}
}
Ok then I have another class DBSQL with the connection to the server and the getid function :
public long getID(String _isin)
{
SqlDataReader rd;
long res = -9999;


SqlCommand cd = new SqlCommand("select astid from blabla where isin='" + _isin + "'", MaConn);
//requète au serveur
try
{
rd = cd.ExecuteReader();

if (rd.HasRows)
{
while (rd.Read())
res = long.Parse(rd["astid"].ToString());
}


And then I have my addin.dna :

<DnaLibrary Name="ClassLibrary Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="ClassLibrary1.dll" LoadFromBytes="true" Pack="true" />
<Reference Path="AccesDB.dll" Pack="true" />

</DnaLibrary>

There are no errors on visual studio but it doesn't work. Excel returns : "NAME?"
Anyone can help please?
A voir également:

1 réponse

si quelqu'un veut la trad en francais, demandez !
merci :-)
0