Msgstr "Compile with / main to specify the type containing the entry point."

Using the code below, I get the following message. I am quite sure why I understand this, I just don’t know how to change the code to move / delete / replace one of the statements that cause the error.

"Compile with / main to specify the type containing the entry point."

There is a bunch of code in "static void Main (string [] args)" that I got from http://support.microsoft.com/kb/816112 to get the identifier from auto-increment so that I can make it auto-increment when the rest of it The code populates the Access database. Any help is appreciated. And suggestions to get results with simpler code are also welcome!

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(); } } } 
+11
source share
4 answers

None of the answers are directly relevant.

The project properties dialog box, accessible by right-clicking on the project, has an Application tab. On this tab, a drop-down list for "Startup Object" - just select the correct class file that Visual Studio should aim at. As long as there is a Main static void event in this class file, it will target it. Make sure Main is capitalized. This will not work:

static void main (string [] args) {... code ...}

Here is the image:

enter image description here

In a web project, you can right-click on an ASPX file and set it as a start page, very similar. Why Visual Studio will bury this option does not make sense, but this is how you do it.

+27
source

If you use Visual Studio to compile / debug your application, you must set the entry point of your program in the properties of your project.
First page → Appendix
Launch Object -> YourNameSpace.WindowsApplication1.Form1

There is no need to reorder the code for this. However, looking at the code provided, I do not see the point in which you start Form1. Inside the main method, there is no code that runs Form1. Sort of

 Application.Run(new Form1()); 
+4
source

The compiler complains that it cannot find a type that implements the entry point of the application (i.e., the Main method), possibly because you have more than one type with compatible Main in your assembly.

One way to solve this problem is to use the /main option, as in /main:Form1 . Of course, if the problem is that there is more than one Main method, the best solution would be to simply remove the ones you are not going to use.

+1
source

I had to do this manually to implement Lox in C #. To "compile with /main " from the command line, I used

 csc /main:Lox.AstPrinter AstPrinter.cs Expr.cs Token.cs TokenType.cs 

or, more generally, if you want to compile the Foo class in the Acme namespace, this also depends on the A.cs, B.cs and C.cs files:

 csc /main:Acme.Foo A.cs B.cs C.cs Foo.cs 
0
source

Source: https://habr.com/ru/post/1403746/


All Articles