我目前有以下代码:
<%@ WebService Language="C#" Class="Notifications" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Script;
using System.Web.Script.Services;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class Notification
{
public int id;
public string text;
public Notification(int m_id, string m_text)
{
id = m_id;
text = m_text;
}
public Notification() {}
}
[System.Web.Script.Services.ScriptService]
public class Notifications : System.Web.Services.WebService {
List<Notification> Notification = new List<Notification>();
[WebMethod()]
public List<Notification> GetNotifications()
{
var notifications = new List<Notification>();
using (SqlConnection objSQLConnection = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connString"]))
{
using (SqlCommand objSQLCommand = new SqlCommand("select * from table1 where col1 = @user", objSQLConnection))
{
objSQLCommand.Parameters.Add("@user", SqlDbType.VarChar, 5).Value = "abc";
objSQLConnection.Open();
using (SqlDataReader objSQLDataReader = objSQLCommand.ExecuteReader())
{
while (objSQLDataReader.Read())
{
notifications.Add(new Notification(objSQLDataReader["id"], objSQLDataReader["text"]));
}
}
}
}
return notifications;
}
}
这给了我以下错误:
Compiler Error Message: CS1502: The best overloaded method match for 'Notification.Notification(int, string)' has some invalid arguments
在线上:
notifications.Add(new Notification(objSQLDataReader["id"], objSQLDataReader["text"]));
有人知道为什么会这样吗?
发布于 2011-08-04 20:23:49
问题是vb代码访问AppSettings
(和一般的数组),如下所示:
AppSettings("keyname")
而c#处理数组的方式如下:
AppSettings["keyname"]
转换器有时很难区分数组和函数。
https://stackoverflow.com/questions/6940815
复制相似问题