帮我看看这个错误提示什么意思啊???到底哪里错了?

blackangel 2005-03-13 02:14:39
///conn.cs///

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;

/// <summary>
/// Summary description for conn
/// </summary>
public class FW:UserControl
{
public SqlConnection objConnection;
public SqlCommand FW(string strSQL)
{
string connectionString = ConfigurationSettings.AppSettings["SqlConStr"];
objConnection = new SqlConnection(connectionString);
SqlCommand objCommand = new SqlCommand(strSQL, objConnection);
objConnection.Open();
return objCommand;
}
public void Close()
{
objConnection.Close();
}
}


-----------------------------------------------------------------
///webconfig.ascx///

<%@ Control Language="C#" Inherits="FW" Src="conn.cs"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>

<script runat="server">
string strSQL = "select * from shop_config";
SqlCommand objCommand = FW(strSQL);
....

</script>

错误提示:
'FW': member names cannot be the same as their enclosing type
...全文
324 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hedonister 2005-03-13
  • 打赏
  • 举报
回复
就是,类必须存在构造函数
老鹰40 2005-03-13
  • 打赏
  • 举报
回复
如果类中的方法成员的名称与类的名称相同的话,那么这个方法应该是所谓的“构造函数”。但构造函数是不能有返回值的,而FW有返回值,故产生错误。
saucer 2005-03-13
  • 打赏
  • 举报
回复
change

public SqlCommand FW(string strSQL)

===>

public SqlCommand GetCommand(string strSQL)


SqlCommand objCommand = FW(strSQL);

==>

SqlCommand objCommand = GetCommand(strSQL);

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧