C# &引用;使用/main编译以指定包含入口点的类型;

C# &引用;使用/main编译以指定包含入口点的类型;,c#,ms-access,auto-increment,C#,Ms Access,Auto Increment,根据下面的代码,我得到以下消息。我很确定我明白了“为什么”,我只是不知道如何重新排列代码来移动/删除/替换其中一个导致错误的语句 “使用/main编译以指定包含入口点的类型。” 在我从中得到的“staticvoidmain(string[]args)”下有一堆代码 为了从auto increment中获取ID,所以当其余代码填充Access数据库时,我可以让它自动递增。感谢您的帮助。同时,我们也欢迎您提出建议,通过更简单的代码获得结果 namespace WindowsFormsApplicat

根据下面的代码,我得到以下消息。我很确定我明白了“为什么”,我只是不知道如何重新排列代码来移动/删除/替换其中一个导致错误的语句

“使用/main编译以指定包含入口点的类型。”

在我从中得到的“staticvoidmain(string[]args)”下有一堆代码 为了从auto increment中获取ID,所以当其余代码填充Access数据库时,我可以让它自动递增。感谢您的帮助。同时,我们也欢迎您提出建议,通过更简单的代码获得结果

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Hazardous Materials\KinneyDatabase.accdb");

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            vcon.Open();

            try
            {
                StreamReader sr = new StreamReader(@"C:\Hazardous Materials\cities.txt");
                string line = sr.ReadLine();

                StreamReader sr2 = new StreamReader(@"C:\Hazardous Materials\drugs.txt");
                string line2 = sr2.ReadLine();

                StreamReader sr3 = new StreamReader(@"C:\Hazardous Materials\strengths.txt");
                string line3 = sr3.ReadLine();

                while (line != null)
                {
                    comboBox1.Items.Add(line);
                    line = sr.ReadLine();
                }
                while (line2 != null)
                {
                    comboBox2.Items.Add(line2);
                    line2 = sr2.ReadLine();
                }
                while (line3 != null)
                {
                    comboBox3.Items.Add(line3);
                    line3 = sr3.ReadLine();
                }
                textBox2.Text = "Date";
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }

        private static OleDbCommand cmdGetIdentity;

        [STAThread]
        static void Main(string[] args)
        {
            // Open Connection
            OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Hazardous Materials\KinneyDatabase.accdb");

            vcon.Open();

            // If the test table does not exist then create the Table
            string strSQL;
            strSQL = "CREATE TABLE AutoIncrementTest " +
                    "(ID int identity, Description varchar(40), " +
                    "CONSTRAINT AutoIncrementTest_PrimaryKey PRIMARY KEY (ID))";

            // Command for Creating Table
            OleDbCommand cmdJetDB = new OleDbCommand(strSQL, vcon);
            cmdJetDB.ExecuteNonQuery();

            // Create a DataAdaptor With Insert Command For inserting records
            OleDbDataAdapter oleDa = new OleDbDataAdapter("Select * from AutoIncrementTest", vcon);


            // Command to Insert Records
            OleDbCommand cmdInsert = new OleDbCommand();
            cmdInsert.CommandText = "INSERT INTO AutoIncrementTest (Description) VALUES (?)";
            cmdInsert.Connection = vcon;
            cmdInsert.Parameters.Add(new OleDbParameter("Description", OleDbType.VarChar, 40, "Description"));
            oleDa.InsertCommand = cmdInsert;

            // Create a DataTable
            DataTable dtTest = new DataTable();
            oleDa.Fill(dtTest);

            DataRow drTest;

            // Add Rows to the Table
            drTest = dtTest.NewRow();
            drTest["Description"] = "This is a Test Row 1";
            dtTest.Rows.Add(drTest);

            drTest = dtTest.NewRow();
            drTest["Description"] = "This is a Test Row 2";
            dtTest.Rows.Add(drTest);

            // Create another Command to get IDENTITY Value
            cmdGetIdentity = new OleDbCommand();
            cmdGetIdentity.CommandText = "SELECT @@IDENTITY";
            cmdGetIdentity.Connection = vcon;

            // Delegate for Handling RowUpdated event
            oleDa.RowUpdated += new OleDbRowUpdatedEventHandler(HandleRowUpdated);

            // Update the Data
            oleDa.Update(dtTest);

            // Drop the table
            cmdJetDB.CommandText = "DROP TABLE AutoIncrementTest";
            cmdJetDB.ExecuteNonQuery();

            // Release the Resources
            cmdGetIdentity = null;
            cmdInsert = null;
            cmdJetDB = null;
            vcon.Close();
            vcon = null;
        }
        // Event Handler for RowUpdated Event
        private static void HandleRowUpdated(object sender, OleDbRowUpdatedEventArgs e)
        {
            if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert )
            {
                // Get the Identity column value
                e.Row["ID"] = Int32.Parse(cmdGetIdentity.ExecuteScalar().ToString());
                System.Diagnostics.Debug.WriteLine(e.Row["ID"]);
                e.Row.AcceptChanges();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex <= 0)
            {
                MessageBox.Show("All fields must be filled out to submit the form");
            }
            else if (comboBox2.SelectedIndex <= 0)
            {
                MessageBox.Show("All fields must be filled out to submit the form");
            }
            string addRemove = "";
            //string toFrom = "";

            if (radioButton1.Checked)
            {
                addRemove = "add";
                //toFrom = "to";
            }
            else if (radioButton2.Checked)
            {
                addRemove = "remove";
                //toFrom = "from";
            }
            float mgTotal = (float.Parse(textBox1.Text) * float.Parse(comboBox3.Text));

            MessageBox.Show("You have entered the following information: \n\n"
                    + "\n" + "Location: " + float.Parse(comboBox1.Text)
                    + "\n" + "Medication: " + comboBox2.Text
                    + "\n" + "Quantity " + textBox2.Text
                    + "\n" + "Strength " + float.Parse(comboBox3.Text)
                    + "\n" + "Initials: " + textBox3.Text
                    + "\n" + "Add or Remove: " + addRemove
                    + "\n" + "Date: " + textBox2.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            new Form2().Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Produced for use by HealthDirect© \n Scripted by Geoff Bertollini. March 2012");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox3.SelectedIndex = comboBox2.SelectedIndex;
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            var date = DateTime.Now.ToString("MM/dd/yyyy");
            textBox2.Text = date;
        }

        private void label4_Click_1(object sender, EventArgs e)
        {

        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string addRemove = "";
            string toFrom = "";

            if (radioButton1.Checked)
            {
                addRemove = "added";
                toFrom = "to";
            }
            else if (radioButton2.Checked)
            {
                addRemove = "removed";
                toFrom = "from";
            }

            float mgTotal = (float.Parse(textBox1.Text) * float.Parse(comboBox3.Text));

            string vsql = string.Format("insert into Log values " +
                    "('{0}','{1}',{2},{3},'{4}',#{5}#,'{6}','{7}')",
                    comboBox1.Text,
                    comboBox2.Text,
                    float.Parse(textBox1.Text),
                    float.Parse(comboBox3.Text),
                    textBox3.Text,
                    textBox2.Text,
                    addRemove,
                    "1"
                    );

            OleDbCommand vcom = new OleDbCommand(vsql, vcon);
            vcom.ExecuteNonQuery();
            MessageBox.Show("Date: " + textBox2.Text + "\n      Initials: " + textBox3.Text
                + "\n" + "You have " + addRemove + " " + mgTotal + " milligrams " + "\n"
                + "of " + comboBox2.Text + "\n" + toFrom + " the inventory of \n" + comboBox1.Text);

            vcom.Dispose();
        }
    }
}
命名空间窗口窗体应用程序1
{
公共部分类Form1:Form
{
OleDbConnection vcon=新的OleDbConnection(@“Provider=Microsoft.ACE.OLEDB.12.0;数据源=C:\Hazardous Materials\KinneyDatabase.accdb”);
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
vcon.Open();
尝试
{
StreamReader sr=新StreamReader(@“C:\Hazardous Materials\cities.txt”);
字符串行=sr.ReadLine();
StreamReader sr2=新StreamReader(@“C:\Hazardous Materials\drugs.txt”);
字符串line2=sr2.ReadLine();
StreamReader sr3=新StreamReader(@“C:\Hazardous Materials\strengths.txt”);
字符串line3=sr3.ReadLine();
while(行!=null)
{
comboBox1.Items.Add(行);
line=sr.ReadLine();
}
while(第2行!=null)
{
comboBox2.Items.Add(第2行);
line2=sr2.ReadLine();
}
while(第3行!=null)
{
comboBox3.Items.Add(第3行);
line3=sr3.ReadLine();
}
textBox2.Text=“日期”;
}
catch(System.Exception-ex)
{
MessageBox.Show(“错误:+ex.Message”);
}
}
私有静态OleDbCommand cmdGetIdentity;
[状态线程]
静态void Main(字符串[]参数)
{
//开放连接
OleDbConnection vcon=新的OleDbConnection(@“Provider=Microsoft.ACE.OLEDB.12.0;数据源=C:\Hazardous Materials\KinneyDatabase.accdb”);
vcon.Open();
//如果测试表不存在,则创建该表
字符串strSQL;
strSQL=“创建表自动递增测试”+
(ID int identity,Description varchar(40)+
“约束自动递增测试_PrimaryKey主键(ID))”;
//用于创建表的命令
OleDbCommand cmdJetDB=新的OleDbCommand(strSQL,vcon);
cmdJetDB.ExecuteNonQuery();
//使用Insert命令创建数据适配器以插入记录
OleDbDataAdapter oleDa=新的OleDbDataAdapter(“从自动增量测试中选择*”,vcon);
//插入记录的命令
OleDbCommand cmdInsert=新的OleDbCommand();
cmdInsert.CommandText=“插入到自动递增测试(描述)值(?);
cmdInsert.Connection=vcon;
添加(新的OLEDBPParameter(“Description”,OleDbType.VarChar,40,“Description”);
oleDa.InsertCommand=cmdInsert;
//创建数据表
DataTable dtTest=新DataTable();
oleDa填充(dtTest);
数据行测试;
//向表中添加行
drTest=dtTest.NewRow();
drTest[“Description”]=“这是一个测试行1”;
dtTest.Rows.Add(drTest);
drTest=dtTest.NewRow();
drTest[“Description”]=“这是一个测试行2”;
dtTest.Rows.Add(drTest);
//创建另一个命令以获取标识值
cmdGetIdentity=新的OleDbCommand();
cmdGetIdentity.CommandText=“选择@@IDENTITY”;
cmdGetIdentity.Connection=vcon;
//用于处理行更新事件的委托
oleDa.RowUpdated+=新的OleDbRowUpdatedEventHandler(HandleRowUpdated);
//更新数据
oleDa.Update(dtTest);
//放下桌子
cmdJetDB.CommandText=“DROP TABLE AutoIncrementTest”;
cmdJetDB.ExecuteNonQuery();
//释放资源
cmdGetIdentity=null;
cmdInsert=null;
cmdJetDB=null;
vcon.Close();
vcon=null;
}
//RowUpdate事件的事件处理程序
私有静态void HandleRowUpdated(对象发送器,OLEDBrownUpdatedEventArgs e)
{
if(e.Status==UpdateStatus.Continue&&e.StatementType==StatementType.Insert)
{
//获取标识列值
e、 行[“ID”]=Int32.Parse(cmdGetIdentity.ExecuteScalar().ToString());
System.Diagnostics.Debug.WriteLine(e.Row[“ID”]);
e、 Row.AcceptChanges();
}
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{

如果(comboBox1.SelectedIndex编译器抱怨找不到实现应用程序入口点的类型(即
Main
方法),可能是因为程序集中有多个类型与
Main
方法

解决此问题的一种方法是使用
/main
选项,如
/main:Form1
中所述。当然,如果问题是存在多个
main
方法,则更好的解决方案是简单地删除您不打算使用的方法。

如果您使用的是Visual Studio
Application.Run(new Form1());
csc /main:Lox.AstPrinter AstPrinter.cs Expr.cs Token.cs TokenType.cs
csc /main:Acme.Foo A.cs B.cs C.cs Foo.cs