等待C#中的用户输入

时间:2011-08-28 06:58:57

标签: c#-4.0

如何使程序停止以插入输入,例如用户名和密码

    "UserId=te; PWD=t57; database=ph3;");

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using MySql.Data.MySqlClient;

    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                MySqlConnection conDatabase = new MySqlConnection("Data Source=localhost;" +
                                           "Persist Security Info=yes;" +
                                           "UserId=te; PWD=t57; database=ph3;");
                conDatabase.Open();
                // MySqlCommand cmdDatabase = new MySqlCommand("DROP TABLE IF EXISTS `q_mem_sur`; create table q_mem_sur as SELECT Count(*) As rowa,  member.Ssurname,  Sum(Case When ((member.status = '1')) Then 1 Else 0 End) As Status11 From member Group By member.Ssurname Order By rowa Desc;", conDatabase);

                string[] arr = new string[12];
                arr[0] = "UPDATE `member` SET `amphurecode`= SUBSTRING(member.own,3,4)";
                arr[1] = "UPDATE `member` SET `provincecode`= SUBSTRING(member.own,3,2)";
                arr[2] = "DROP TABLE IF EXISTS `q_mem_tim`; create table q_mem_tim as SELECT member.idmember, member.own, member.provincecode, province.PROVINCE_NAME, member.amphurecode, amphur.AMPHUR_NAME, member.novote, member.Sname, member.Ssurname, member.Hno, member.Moo, member.Sex, member.tambol, member.dateofbirth, member.migratedate, Year( Current_Date( ) ) -  Year( member.dateofbirth ) AS y,  DATEDIFF('2011-08-01',(migratedate)) AS d FROM member LEFT JOIN amphur ON ( member.amphurecode  = amphur.AMPHUR_CODE ) LEFT JOIN province ON member.provincecode  = province.PROVINCE_CODE";

                arr[10] = "UPDATE q_mem_birth SET agec = CASE WHEN y < 10 THEN '¿'  WHEN y > 10 and y < 20 and Sex='¿' THEN  '¿¿'  WHEN y > 10 and y < 20 and Sex='¿' THEN  '¿¿'   ELSE '¿¿' END";
                arr[11] = "drop table if exists q_mem_birth; create table q_mem_birth as SELECT q_mem_tim.idmember,q_mem_tim.own,q_mem_tim.PROVINCE_NAME,q_mem_tim.AMPHUR_NAME,q_mem_tim.novote,q_mem_tim.Sname,q_mem_tim.Ssurname,q_mem_tim.Hno,q_mem_tim.Moo,q_mem_tim.Sex,q_mem_tim.tambol,q_mem_tim.dateofbirth,q_mem_tim.migratedate,q_mem_tim.y,q_mem_tim.d,q_mem_tim.agec FROM q_mem_tim where  q_mem_tim.dateofbirth is not null and q_mem_tim.dateofbirth != '00000000' and day(q_mem_tim.dateofbirth) != '00' and day(q_mem_tim.dateofbirth) > 0 and day(q_mem_tim.dateofbirth) < 11 and month(q_mem_tim.dateofbirth) != '00'   and month(q_mem_tim.dateofbirth) > 8 and month(q_mem_tim.dateofbirth) < 10 order by tambol,Moo, month(dateofbirth),day(dateofbirth)  ";

                foreach (string s in arr)
                {
                    Console.WriteLine(s);
                    MySqlCommand cmdDbase = new MySqlCommand((s), conDatabase);
                    cmdDbase.CommandTimeout = 500;
                    cmdDbase.ExecuteNonQuery();
                }
                conDatabase.Close();
            }

        }
    }

1 个答案:

答案 0 :(得分:3)

您可能想要使用Console.ReadLine();方法。有关详细信息,请参阅 Console.ReadLine Method (MSDN)。

这样的事情:

Console.WriteLine("Enter username");
string uname=Console.ReadLine();