解决方案 »

  1.   

    控制台不是有Console.ReadLine()吗
    一步一步的,先用Console.WriteLine()提示用户现在要输入什么了,然后用户输入完读出来放变量里
      

  2.   

    你能不能帮我做一个示范呢,这是窗体里面的ATM,我不想修改什么  帮我看看怎么改下 谢谢你
     //定义一个静态公关全局变量
             public static int MyKahao;        private void button1_Click(object sender, EventArgs e)
            {
                //第一步:指定连接的数据库
                SqlConnection conn= new SqlConnection("server=HHY-PC\\HHY;uid=sa;pwd=123456;database=YangATM_DB");            //第二步:需要执行的SQL语句
                string sql = "select * from KaiHuInFo where KaHao='" + txtkahao.Text + "' and KaMiMa='" + txtmima.Text + "'";            //第三步:申明一个数据适配器用于解析SQL语句的,且开始解析SQL语句
              
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);            //第四步:申明一个数据集
                DataSet ds = new DataSet();
                //Console.WriteLine("请输入卡号");
                //第五步:将查询的结果存放到数据集中
                da.Fill(ds);          
                if (ds.Tables[0].Rows.Count > 0)
                {
                    MessageBox.Show("登录成功");
                                   //获取文本框内的值并赋值
                    MyKahao = Convert.ToInt32(txtkahao.Text);
                    QuKuanJianMian qk = new QuKuanJianMian();
                    qk.Show();                this.Hide();
                }
                else
                {
                 MessageBox.Show("输入的账号或密码不正确");
                 txtkahao.Text = "";
                 txtmima.Text = "";
                }
                
      

  3.   

    "不想修改什么"的前提是你已经封装好了方法,可以在winform和console里都能直接调用
    而你现在本身就是把代码直接放到按钮事件里去,而控制台里根本没有所谓按钮事件,那么不改势必是不可能的
      

  4.   

    你至少要先把函数封装成这种格式:
    void function(string text1,string text2){}
    然后针对不同的项目,两个字符串从哪里来不一样而已,最终都是传入字符串之后调用函数
    否则你整个代码已经跟控件耦合在一起,不改不行的
      

  5.   


    你们有没有完成的控制台ATM已经连接好的数据库,最好是vs2010打开的  谁有请发我一份  我有较多积分供你们下载其他资料
      

  6.   

    class program
    {
    static void Main(string[] args)
    {
    string userInput="";
    Console.WriteLine("Please input your Account:");
    userInput = Console.ReadLine();
    int iAccount = -1;
    if(!int.TryParse(userInput, out iAccount)) 
    {
    Console.WriteLine("Account is not Correct.");
    return;
    }

    Console.WriteLine("Please input your Password:");
    userInput = Console.ReadLine();

    if(userInput.Trim().length == 0)
    {
    Console.WriteLine("Password error.");
    return;
    }
    string password = userInput;

    DummyTextBox txtkahao = new DummyTextBox(iAccount + "");
    DummyTextBox txtmima = new DummyTextBox(password);

    // copy you code here.
    }
    }class DummyTextBox
    {
    public DummyTextBox()
    {
    }

    public DummyTextBox(string text)
    {
    this.Text = text;
    }

    public string Text;
    }
      

  7.   

    另外,注意下sql注入的问题,直接拼接sql文会有sql注入的风险。
    还有,你们密码都是明文存数据库的???!!!!
    连接字符串连的数据库希望是测试数据库而不是真正的生产环境,不然直接sa连阿,密码还看得到阿。。最后,console如果要调用messagebox之类的winform的东西,记得加参照
      

  8.   

    你们谁上传几个完成的控制台ATM已经连接好的SQLserver数据库,最好是vs2010打开的
      

  9.   

    不要这么写sql语句,容易出问题,而且容易被攻击。要使用SqlParameter :
    https://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlparameter(v=vs.110).aspx