我如何解决错误是“ .exe不包含适用于入口点的静态“Main”方法。 [英] How do I solve the error is that " .exe does not contain a static 'Main' method suitable for an entry point".

查看:92
本文介绍了我如何解决错误是“ .exe不包含适用于入口点的静态“Main”方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好,我在调试程序时总是遇到错误,错误是DataBaseProject.exe不包含适合入口点的静态'Main'方法,甚至我将其属性从Console Application更改为类库,然后它的构建成功,但它不能正常工作,并没有显示在控制台窗口。所以请帮我解决我的这个问题。下面是代码:





Hello everybody, I always got the error while I debug my program and the error is that "DataBaseProject.exe does not contain a static 'Main' method suitable for an entry point" and even I change its properties from Console Application to Class Library, then its build successfully but it does not work well and nothing show on the console window.So please help me to solve my this issue.Here's below is the code:


class Program
   {
       static void Main(string[] args)
       {
           int choice = 0;
           do
           {
               Console.WriteLine(" 1)Enter 1 to add a student.");
               Console.WriteLine(" 2)Enter 2 to view the all student.");
               Console.WriteLine(" 3)enter 3 to delete a student.");
               Console.WriteLine(" 4)enter 4 to exit");
               Console.Write("pleaswe enter your choice :");
               choice = Convert.ToInt32(Console.ReadLine());
               switch (choice)
               {
                   case 1:
                      Addstudent();
                       break;
                   case 2:
                      viewstudent();
                       break;
                   case 3:
                      deletestudent();
                       break;
               }
           } while (choice != 4 );
       }


         static void Addstudent()
          {
           Console.Write("enter the student name");
           string  name = Console.ReadLine();
           System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection();
           connection.ConnectionString = @"Data Source=ps201\sqlexpress;Initial Catalog=Info_studednt;Integrated Security=True;Pooling=False";
           System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
           command.Connection = connection;
           connection.Open();
           command.CommandText = "insert into student (name) values (' " + name + " ')";
           int rowAffected = command.ExecuteNonQuery();
           if (rowAffected != 0)
           {
               Console.WriteLine("Error:student not inserted..");
           }
           else
           {
               Console.WriteLine("Sucess:student insert successfully..");
           }

        }
            static void viewstudent()
            {
                System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection();
                connection.ConnectionString = @"Data Source=ps201\sqlexpress;Initial Catalog=Info_studednt;Integrated Security=True;Pooling=False";
                System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
                command.Connection = connection;
                command.CommandText = "selsct * from student";
                System.Data.SqlClient.SqlDataReader dr = command.ExecuteReader();
                Console.WriteLine("rollno \t name");
                while (dr.Read())
                {
                    Console.Write(dr["name"] + ":" + dr["rollno"]);
                }
            }

          static void deletestudent()
          {
              Console.Write("enter the student rollno");
              string rollno = Console.ReadLine();
              System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection();
              connection.ConnectionString = @"Data Source=ps201\sqlexpress;Initial Catalog=Info_studednt;Integrated Security=True;Pooling=False";
              System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
              command.Connection = connection;
              command.CommandText = "delete from student where =(' " + rollno + " ')";
              int rowAffected = command.ExecuteNonQuery();
              if (rowAffected != 0)
              {
                  Console.WriteLine("Error:student not deleted..");
              }
              else
              {
                  Console.WriteLine("Sucess:student deeleted  successfully..");
              }

          }

推荐答案

这应该作为控制台应用程序 - 除了我通常期望一个命名空间和一个类。

尝试确保你在文件的顶部有这个:

That should work as a console app - with the exception that I'd normally expect a Namespace as well as a class.
Try making sure that you have this at the top of the file:
using System;

namespace TCFConsole
    {

最后匹配的}。



和BTW:SELECT只有一个s:

And a matching "}" at the end.

And BTW: SELECT has only one "s":

command.CommandText = "selsct * from student";
                          ^







哦,你能不能给我是参数化查询的简短示例,以及我需要如何编写代码以及我需要提及的内容,因为我是C#的新手。






"Okey, can you please give me the brief example of parameterised query and how I need to write its code and what I need to mention there, because I am new to C#."

using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
        {
        cmd.Parameters.AddWithValue("@C1", myValueForColumn1);
        cmd.Parameters.AddWithValue("@C2", myValueForColumn2);
        cmd.ExecuteNonQuery();
        }
    }


这篇关于我如何解决错误是“ .exe不包含适用于入口点的静态“Main”方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆