正如标题所示,这是我的第一个C#尝试,所以请放轻松.(作为一个新手,我保证会为C#专业人员提出一些简单的问题,以便为您提供一些简单的观点!)我正在使用ExcelDNA在Excel中创建一个UDF,它将查询我们的mysql数据库.我添加了ExcelDNA和mysql连接器dll作为参考.我有以下代码,它会产生一些错误:
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"; …Run Code Online (Sandbox Code Playgroud)