As the title suggest, this is my first C# try, so please go easy. (As a newb I promise to ask a bunch of easy questions for the C# pros out there to get you some easy points!) I'm using ExcelDNA to create a UDF in Excel, which will query our mysql database. I've added the ExcelDNA and mysql connector dll's as references. I have the following code, which produces a few errors:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;
using ExcelDna.Integration;
using MySql.Data.MySqlClient;
namespace my_test
{
public partial class ThisAddIn
{
[ExcelFunction(Description = "Multiplies two numbers", Category = "Useful functions")]
public static MultiplyThem(string[] args)
{
string connString = "Server=localhost;Port=3306;Database=test;Uid=root;password=p-word";
MySqlConnection conn = new MySqlConnection(connString);
MySqlCommand command = conn.CreateCommand();
command.CommandText = "SELECT field_value FROM customers";
try
{
conn.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
string myvariable = "bad";
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
myvariable = reader["field_value"].ToString;
}
return myvariable.ToString;
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
}
}
Here's the errors:
Error 1 Cannot convert method group 'ToString' to non-delegate type 'double'. Did you intend to invoke the method?
Error 2 Method must have a return type
Error 3 Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method?
Error 4 Since 'my_test.ThisAddIn.MultiplyThem(string[])' returns void, a return keyword must not be followed by an object expression