为什么会出现这些错误,以及如何解决这些错误?
错误1预期的类,委托,枚举,接口或结构C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ lomdb \ EnterData \ DataEntry \ DAL.cs 9 19 EnterData
错误2预期的类,委托,枚举,接口或结构C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ lomdb \ EnterData \ DataEntry \ DAL.cs 11 54 EnterData
错误3预期的类,委托,枚举,接口或结构C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ lomdb \ EnterData \ DataEntry \ DAL.cs 25 23 EnterData
错误4预期的类,委托,枚举,接口或结构C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ lomdb \ EnterData \ DataEntry \ DAL.cs 27 57 EnterData
错误5类型或命名空间定义,或预期文件结束C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 208 \ Projects \ lomdb \ EnterData \ DataEntry \ DAL.cs 39 9 EnterData
错误8当前上下文中不存在名称“PopulateMainForm”C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ lomdb \ EnterData \ DataEntry \ WebForm1.aspx.cs 25 53 EnterData < / p>
错误9当前上下文中不存在名称“PopulateBatchTable”C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ lomdb \ EnterData \ DataEntry \ WebForm1.aspx.cs 26 50 EnterData < / p>
错误10当前上下文中不存在名称“PopulateProblemTable”C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ lomdb \ EnterData \ DataEntry \ WebForm1.aspx.cs 27 54 EnterData < / p>
错误11当前上下文中不存在名称“PopulateSpecimenTable”C:\ Documents and Settings \ agordon \ My Documents \ Visual Studio 2008 \ Projects \ lomdb \ EnterData \ DataEntry \ WebForm1.aspx.cs 28 56 EnterData < / p>
我将IList类保存在同一目录中名为DAL.cs的文件中:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RadarGraphInsertDLL;
namespace EnterData.DataEntry
{
public static IList<LOMDLL.Lom_Batch> PopulateBatchTable()
{
IList<LOMDLL.Lom_Batch> BatchTable = new IList<LOMDLL.Lom_Batch>();
try
{
}
catch (Exception e)
{
}
return BatchTable;
}
public static IList<LOMDLL.Lom_Problem> PopulateProblemTable()
{
IList<LOMDLL.Lom_Problem ProblemTable = new IList<LOMDLL.Lom_Problem();
try
{
}
catch (Exception e)
{
}
return ProblemTable;
}
public static IList<LOMDLL.Lom_Specimen> PopulateSpecimenTable()
{
IList<LOMDLL.Lom_Specimen SpecimenTable = new IList<LOMDLL.Lom_Specimen();
try
{
}
catch (Exception e)
{
}
return SpecimenTable;
}
public static LOMDLL.Main_Lom_Form PopulateMainForm()
{
//populate class
LOMDLL.Main_Lom_Form TheForm = new LOMDLL.Main_Lom_Form();
try
{
TheForm.lom_number = lom_numberTextBox.Text.ToInt();
TheForm.identified_by = identified_byTextBox.Text;
TheForm.occurrence_date = occurrence_dateTextBox.Text.ToDateTime();
//TheForm.pre_contact = pre_contactTextBox.Text; //need to create this texdtbox
//TheForm.pre_practice_code = pre_practice_codeTextBox.Text; //create this
TheForm.report_by = report_byTextBox.Text;
TheForm.report_date = report_dateTextBox.Text.ToDateTime();
TheForm.section_c_comments = section_c_commentsTextBox.Text;
TheForm.section_c_issue_error_identified_by = section_c_issue_error_identified_byTextBox.Text;
TheForm.section_d_investigation = section_d_investigationTextBox.Text;
TheForm.section_e_corrective_action = section_e_corrective_actionTextBox.Text;
TheForm.section_f_comments = section_f_commentsTextBox.Text;
}
catch(Exception e)
{
}
return TheForm;
}
}
答案 0 :(得分:4)
您的代码无效。您不能在命名空间范围内声明方法,它们必须驻留在类(或其他类型)定义中。
namespace EnterData.DataEntry
{
public class Foo
{
public static IList<LOMDLL.Lom_Batch> PopulateBatchTable()
{
// code here...
}
}
}
答案 1 :(得分:4)
DAL.cs有一个直接包含方法声明的命名空间。命名空间可能不包含方法声明。允许命名空间包含类,委托,枚举,接口,结构或其他名称空间。 因此出现了类,委托,枚举,接口或结构的错误消息。
你想要的是一个静态类:
namespace DataEntry
{
static class MyClass
{
public static IList<LOMDLL.Lom_Batch> PopulateBatchTable()
{ ... }
}
}
然后拨打MyClass.PopulateBatchTable()
。
答案 2 :(得分:4)
在DAL.cs中,你缺少一个类声明:
namespace EnterData.DataEntry
{
public static class DAL // Add Class Here
{
public static IList<LOMDLL.Lom_Batch> PopulateBatchTable()
{
然后在你的webform中,你需要使用类名来调用静态函数
...
protected void SubmitData(object sender, EventArgs e)
{
LOMDLL.Main_Lom_Form MainLomFormTable = DAL.PopulateMainForm(); // Add DAL.
答案 3 :(得分:1)
无法在类定义之外声明函数。你所做的是声明一组没有类定义的函数。
通常这适用于模块形式的Visual Basic(在非网络世界中)。
因为,我不能评论那里的第一个答案,我只是发布一个新答案。 的