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

2024-04-12

根据下面的代码,我收到以下消息。我相当确定“为什么”我得到它,我只是不知道如何重新排列代码以移动/删除/替换导致错误的语句之一。

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

下面有一堆代码“静态无效主(字符串[]参数)”,我从http://support.microsoft.com/kb/816112 http://support.microsoft.com/kb/816112为了从自动增量中获取 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();
        }
    }
}

没有一个答案能切中要点。

右键单击项目即可访问项目的属性对话框,其中有一个“应用程序”选项卡。在此选项卡上有一个“启动对象”下拉列表 - 只需选择 Visual Studio 应定位的正确类文件即可。只要该类文件中存在 Main static void 事件,它就会以它为目标。确保 Main 是大写的。这是行不通的:

静态无效主(字符串[]参数) { ... 代码 ... }

这是一张图片:

在 Web 项目中,您可以右键单击 ASPX 文件并将其设置为启动页面,非常类似的事情。为什么 Visual Studio 隐藏此设置没有意义,但这就是您执行此操作的方法。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“使用 /main 进行编译以指定包含入口点的类型。” 的相关文章

  • 数字或货币的字符串格式?

    我需要为每个千给出逗号 所以我用了DataFormatString 0 它运行良好 但当值为0 它正在显示 00 我只想只显示 0 我们怎样才能做到这一点 DataFormatString 0 C0 这将格式化为小数点后 0 位的货币 Da
  • 异步提交或回滚事务范围

    正如许多人所知 TransactionScope当async await Net 中引入了模式 如果我们尝试使用一些它们就会损坏await在事务范围内调用 现在这个问题已经解决了 感谢范围构造函数选项 a 17527759 1178314
  • 返回带有列表对象的列表对象

    我有三个表 汽车品牌 汽车型号 和 CarsandModel 我有 Carsand 模型表 因为一个模型可以由多个制造商构建 我想返回包含汽车型号列表的汽车品牌列表 我现在的长篇大论不是过滤汽车型号的汽车制造商列表 我尝试添加一个 wher
  • C 语言的符号表

    我目前正在开发一种执行模式匹配的静态分析工具 我在用Flex https github com westes flex生成词法分析器 我编写了代码来管理符号表 我不太有经验C 所以我决定将符号表实现为线性链表 include
  • Java 相当于 C# 的 async/await?

    我是一名普通的 C 开发人员 但偶尔也会使用 Java 开发应用程序 我想知道 Java 中是否有相当于 C async await 的东西 简单来说 java 相当于 async Task
  • esp8266互联网交换机问题

    我正在尝试制作一个门继电器开关系统 我可以通过端口转发从任何地方进行操作 我找到了一个非常有用的指南和代码 我的程序基于 https openhomeautomation net control a lamp remotely using
  • 三元运算的结果(类型)是什么?

    三元运算是否返回副本或引用 我检查了以下代码 vector
  • DirectX Vertex 中的 THE 是什么

    我知道 RHW 是倒数同质 W 但有人可以解释一下它的使用方法和作用吗 gamedev论坛上的说明post http www gamedev net topic 440283 reciprocal of homogeneous w and
  • 在 C99 中,f()+g() 是未定义还是只是未指定?

    我曾经认为在C99中 即使函数的副作用f and g干扰 虽然表达f g 不包含序列点 f and g将包含一些 因此行为将是未指定的 要么 f 在 g 之前调用 要么 g 在 f 之前调用 我不再那么确定了 如果编译器内联函数会怎样 即使
  • 如何用C语言创建字典?

    我正在用 C 语言编写一个微控制器 作为它的一部分 我想在 7 段显示器上显示某些字母 每个字母都有一个对应的数字 使 7 段显示屏显示该字母 它没有真正的模式 因为数字只是通过将显示字母所需的 7 段显示器上的位相加而成 因此如果我可以创
  • 将 boost::iostreams::mapped_file_source 与 std::multimap 一起使用

    我有相当大量的数据需要分析 每个文件大约有 5gig 每个文件的格式如下 xxxxx yyyyy 键和值都可以重复 但键是按升序排列的 我正在尝试使用内存映射文件来实现此目的 然后找到所需的键并使用它们 这是我写的 if data file
  • 在.NET MVC中,有没有一种简单的方法来检查我是否在主页上?

    如果用户从主页登录 我需要采取特定的操作 在我的 LogOnModel 中 我有一个隐藏字段 Html Hidden returnUrl Request Url AbsoluteUri 在我的控制器中 我需要检查该值是否是主页 在下面的示例
  • 确定所选电子邮件是来自收件箱还是已发送邮件

    我正在编程Outlook 插件并需要确定所选电子邮件是否来自Inbox or Sent Items这样当我将电子邮件保存到数据库中时 我可以使用文件夹 收件箱 或 已发送 来标记电子邮件 我知道我可以将文件夹名称与 收件箱 或 已发送邮件
  • 找到两个值的平均值的正确方法是什么?

    我最近了解到整数溢出是 C 中的未定义行为 附带问题 C 中也是 UB 吗 在 C 编程中 您通常需要求两个值的平均值a and b 然而做 a b 2可能会导致溢出和未定义的行为 所以我的问题是 找到两个值的平均值的正确方法是什么a an
  • Visual Studio 扩展找不到所需的程序集

    我为 Visual Studio 2013 编写了一个扩展 因为该死的组合框错误 https stackoverflow com questions 7800032 cancel combobox selection in wpf with
  • 如果未先将 lambda 表达式强制转换为委托或表达式树类型,则无法将其用作动态分派操作的参数

    我正在使用 NET4 5 和 VS2013 我有这个查询dynamic来自数据库的结果 dynamic topAgents this dataContext Sql select t create user id as User sum t
  • 是否可以在 ASP.NET Web API 和 SPA 中使用基于 cookie 的身份验证?

    我想创建基于 angularjs 前端和 ASP NET Web API 的 Web 应用程序 我需要创建安全 api 但我无法在将实施此 Web 应用程序的公司服务器上使用基于令牌的身份验证 是否可以对 SPA 和 ASP NET Web
  • 如何获取 (Linux) 机器的 IP 地址?

    这个问题和之前问的几乎一样如何获取本地计算机的IP地址 https stackoverflow com questions 122208 get the ip address of local computer 问题 但是我需要找到一个的I
  • 复杂对象上的 GroupBy(例如 List

    Using GroupBy and Count gt 1我试图在列表中查找我的类的重复实例 该类看起来像这样 public class SampleObject public string Id public IEnumerable
  • C++ 中带逗号的表达式的执行顺序 [重复]

    这个问题在这里已经有答案了 我的理解是这个词j i将在之前执行 i在声明中 j i i C 标准是否保证j i将在之前执行 i在循环 for auto i std next begin j begin i end j i i 逗号运算符引入

随机推荐