c# – “使用/ main编译以指定包含入口点的类型.”

前端之家收集整理的这篇文章主要介绍了c# – “使用/ main编译以指定包含入口点的类型.”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
根据下面的代码,我收到以下消息.我很确定“为什么”我得到它,我只是不知道如何重新排列代码来移动/删除/替换其中一个错误导致语句.

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

在“static void Main(string [] args)”下面有一堆代码,我是从中得到的
http://support.microsoft.com/kb/816112
为了从自动增量中获取ID,所以当剩下的代码填充Access数据库时,我可以自动增加它.任何帮助表示赞赏.我们也欢迎使用更简单的代码获得结果的建议!

  1. namespace WindowsFormsApplication1
  2. {
  3. public partial class Form1 : Form
  4. {
  5. OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Hazardous Materials\KinneyDatabase.accdb");
  6.  
  7. public Form1()
  8. {
  9. InitializeComponent();
  10. }
  11.  
  12. private void Form1_Load(object sender,EventArgs e)
  13. {
  14. vcon.Open();
  15.  
  16. try
  17. {
  18. StreamReader sr = new StreamReader(@"C:\Hazardous Materials\cities.txt");
  19. string line = sr.ReadLine();
  20.  
  21. StreamReader sr2 = new StreamReader(@"C:\Hazardous Materials\drugs.txt");
  22. string line2 = sr2.ReadLine();
  23.  
  24. StreamReader sr3 = new StreamReader(@"C:\Hazardous Materials\strengths.txt");
  25. string line3 = sr3.ReadLine();
  26.  
  27. while (line != null)
  28. {
  29. comboBox1.Items.Add(line);
  30. line = sr.ReadLine();
  31. }
  32. while (line2 != null)
  33. {
  34. comboBox2.Items.Add(line2);
  35. line2 = sr2.ReadLine();
  36. }
  37. while (line3 != null)
  38. {
  39. comboBox3.Items.Add(line3);
  40. line3 = sr3.ReadLine();
  41. }
  42. textBox2.Text = "Date";
  43. }
  44. catch (System.Exception ex)
  45. {
  46. MessageBox.Show("Error: " + ex.Message);
  47. }
  48. }
  49.  
  50. private static OleDbCommand cmdGetIdentity;
  51.  
  52. [STAThread]
  53. static void Main(string[] args)
  54. {
  55. // Open Connection
  56. OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Hazardous Materials\KinneyDatabase.accdb");
  57.  
  58. vcon.Open();
  59.  
  60. // If the test table does not exist then create the Table
  61. string strsql;
  62. strsql = "CREATE TABLE AutoIncrementTest " +
  63. "(ID int identity,Description varchar(40)," +
  64. "CONSTRAINT AutoIncrementTest_PrimaryKey PRIMARY KEY (ID))";
  65.  
  66. // Command for Creating Table
  67. OleDbCommand cmdJetDB = new OleDbCommand(strsql,vcon);
  68. cmdJetDB.ExecuteNonQuery();
  69.  
  70. // Create a DataAdaptor With Insert Command For inserting records
  71. OleDbDataAdapter oleDa = new OleDbDataAdapter("Select * from AutoIncrementTest",vcon);
  72.  
  73.  
  74. // Command to Insert Records
  75. OleDbCommand cmdInsert = new OleDbCommand();
  76. cmdInsert.CommandText = "INSERT INTO AutoIncrementTest (Description) VALUES (?)";
  77. cmdInsert.Connection = vcon;
  78. cmdInsert.Parameters.Add(new OleDbParameter("Description",OleDbType.VarChar,40,"Description"));
  79. oleDa.InsertCommand = cmdInsert;
  80.  
  81. // Create a DataTable
  82. DataTable dtTest = new DataTable();
  83. oleDa.Fill(dtTest);
  84.  
  85. DataRow drTest;
  86.  
  87. // Add Rows to the Table
  88. drTest = dtTest.NewRow();
  89. drTest["Description"] = "This is a Test Row 1";
  90. dtTest.Rows.Add(drTest);
  91.  
  92. drTest = dtTest.NewRow();
  93. drTest["Description"] = "This is a Test Row 2";
  94. dtTest.Rows.Add(drTest);
  95.  
  96. // Create another Command to get IDENTITY Value
  97. cmdGetIdentity = new OleDbCommand();
  98. cmdGetIdentity.CommandText = "SELECT @@IDENTITY";
  99. cmdGetIdentity.Connection = vcon;
  100.  
  101. // Delegate for Handling RowUpdated event
  102. oleDa.RowUpdated += new OleDbRowUpdatedEventHandler(HandleRowUpdated);
  103.  
  104. // Update the Data
  105. oleDa.Update(dtTest);
  106.  
  107. // Drop the table
  108. cmdJetDB.CommandText = "DROP TABLE AutoIncrementTest";
  109. cmdJetDB.ExecuteNonQuery();
  110.  
  111. // Release the Resources
  112. cmdGetIdentity = null;
  113. cmdInsert = null;
  114. cmdJetDB = null;
  115. vcon.Close();
  116. vcon = null;
  117. }
  118. // Event Handler for RowUpdated Event
  119. private static void HandleRowUpdated(object sender,OleDbRowUpdatedEventArgs e)
  120. {
  121. if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert )
  122. {
  123. // Get the Identity column value
  124. e.Row["ID"] = Int32.Parse(cmdGetIdentity.ExecuteScalar().ToString());
  125. System.Diagnostics.Debug.WriteLine(e.Row["ID"]);
  126. e.Row.AcceptChanges();
  127. }
  128. }
  129. private void button1_Click(object sender,EventArgs e)
  130. {
  131. if (comboBox1.SelectedIndex <= 0)
  132. {
  133. MessageBox.Show("All fields must be filled out to submit the form");
  134. }
  135. else if (comboBox2.SelectedIndex <= 0)
  136. {
  137. MessageBox.Show("All fields must be filled out to submit the form");
  138. }
  139. string addRemove = "";
  140. //string toFrom = "";
  141.  
  142. if (radioButton1.Checked)
  143. {
  144. addRemove = "add";
  145. //toFrom = "to";
  146. }
  147. else if (radioButton2.Checked)
  148. {
  149. addRemove = "remove";
  150. //toFrom = "from";
  151. }
  152. float mgTotal = (float.Parse(textBox1.Text) * float.Parse(comboBox3.Text));
  153.  
  154. MessageBox.Show("You have entered the following information: \n\n"
  155. + "\n" + "Location: " + float.Parse(comboBox1.Text)
  156. + "\n" + "Medication: " + comboBox2.Text
  157. + "\n" + "Quantity " + textBox2.Text
  158. + "\n" + "Strength " + float.Parse(comboBox3.Text)
  159. + "\n" + "Initials: " + textBox3.Text
  160. + "\n" + "Add or Remove: " + addRemove
  161. + "\n" + "Date: " + textBox2.Text);
  162. }
  163.  
  164. private void button2_Click(object sender,EventArgs e)
  165. {
  166. new Form2().Show();
  167. }
  168.  
  169. private void button3_Click(object sender,EventArgs e)
  170. {
  171. Application.Exit();
  172. }
  173.  
  174. private void toolStripMenuItem1_Click(object sender,EventArgs e)
  175. {
  176. MessageBox.Show("Produced for use by HealthDirect© \n Scripted by Geoff Bertollini. March 2012");
  177. }
  178.  
  179. private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)
  180. {
  181.  
  182. }
  183.  
  184. private void comboBox2_SelectedIndexChanged(object sender,EventArgs e)
  185. {
  186. comboBox3.SelectedIndex = comboBox2.SelectedIndex;
  187. }
  188. private void textBox2_TextChanged(object sender,EventArgs e)
  189. {
  190. var date = DateTime.Now.ToString("MM/dd/yyyy");
  191. textBox2.Text = date;
  192. }
  193.  
  194. private void label4_Click_1(object sender,EventArgs e)
  195. {
  196.  
  197. }
  198.  
  199. private void exitToolStripMenuItem1_Click(object sender,EventArgs e)
  200. {
  201. Application.Exit();
  202. }
  203.  
  204. private void button4_Click(object sender,EventArgs e)
  205. {
  206. string addRemove = "";
  207. string toFrom = "";
  208.  
  209. if (radioButton1.Checked)
  210. {
  211. addRemove = "added";
  212. toFrom = "to";
  213. }
  214. else if (radioButton2.Checked)
  215. {
  216. addRemove = "removed";
  217. toFrom = "from";
  218. }
  219.  
  220. float mgTotal = (float.Parse(textBox1.Text) * float.Parse(comboBox3.Text));
  221.  
  222. string vsql = string.Format("insert into Log values " +
  223. "('{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"
  224. );
  225.  
  226. OleDbCommand vcom = new OleDbCommand(vsql,vcon);
  227. vcom.ExecuteNonQuery();
  228. MessageBox.Show("Date: " + textBox2.Text + "\n Initials: " + textBox3.Text
  229. + "\n" + "You have " + addRemove + " " + mgTotal + " milligrams " + "\n"
  230. + "of " + comboBox2.Text + "\n" + toFrom + " the inventory of \n" + comboBox1.Text);
  231.  
  232. vcom.Dispose();
  233. }
  234. }
  235. }

解决方法

没有一个答案直截了当.

通过右键单击项目访问的项目属性Dialog具有“应用程序”选项卡.在此选项卡上有一个“启动对象”的下拉列表 – 只需选择Visual Studio应该定位的正确类文件.只要该类文件中存在Main静态void事件,它就会以它为目标.确保Main是大写的.这不起作用:

static void main(string [] args)
{
……代码……
}

这是一张图片

在Web项目中,您可以右键单击ASPX文件并将其设置为启动页面,非常相似.为什么Visual Studio掩盖此设置没有意义,但这就是你如何做到这一点.

猜你在找的C#相关文章