“Compile with /main to specify the type that contains the entry point.”
根据下面的代码,我收到以下消息。我相当肯定"为什么"我得到了它,我只是不知道如何重新排列代码来移动/删除/替换其中一个导致错误的语句。
"使用/main编译以指定包含入口点的类型。"
在"static void main(string[]args)"下面有一堆代码,我从中得到http://support.microsoft.com/kb/816112为了从auto increment中获取ID,所以当其余代码填充访问数据库时,可以让它自动递增。感谢您的帮助。同时也欢迎使用更简单的代码获得结果的建议!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | 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: " +" " +"Location:" + float.Parse(comboBox1.Text) +" " +"Medication:" + comboBox2.Text +" " +"Quantity" + textBox2.Text +" " +"Strength" + float.Parse(comboBox3.Text) +" " +"Initials:" + textBox3.Text +" " +"Add or Remove:" + addRemove +" " +"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? 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 +" Initials:" + textBox3.Text +" " +"You have" + addRemove +"" + mgTotal +" milligrams" +" " +"of" + comboBox2.Text +" " + toFrom +" the inventory of " + comboBox1.Text); vcom.Dispose(); } } } |
所有的答案都没有直截了当。
通过右键单击项目可访问项目的"属性"对话框,其中有一个"应用程序"选项卡。在这个选项卡上有一个"启动对象"下拉列表——只需选择Visual Studio应该指向的正确类文件。只要该类文件中有一个主要的静态void事件,它就会以它为目标。请确保MAIN大写。这行不通:
静态void main(string[]args){…代码…}
这是一张图片:
在一个Web项目中,您可以右键单击一个ASPX文件,并将其设置为启动页,非常类似。为什么Visual Studio会隐藏此设置没有意义,但这是您的做法。
如果使用Visual Studio编译/调试应用程序,则应在项目的属性中设置程序的入口点。首页->应用程序启动对象->yournamespace.windowsapplication1.form1
没有必要为此重新排列代码。但是,查看提供的代码,我看不到您在其中启动Form1的任何点。主方法内部缺少启动Form1的代码。类似的东西
1 |
编译器抱怨它找不到实现应用程序入口点的类型(即
解决这一问题的一种方法是使用