zoukankan      html  css  js  c++  java
  • Form1.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;

    namespace _001
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                string sql = "select count(*) from tbusers where loginid=@loginid and loginpwd=@loginpwd";
                SqlParameter[] pms = new SqlParameter[]{
                new SqlParameter("@loginid",SqlDbType.VarChar,50){Value=textBox1.Text.Trim()},
                new SqlParameter("@loginpwd",SqlDbType.VarChar,50){Value=textBox2.Text.Trim()}
                };
                int i=(int)SqlHelper.ExecuteScalar(sql,pms);
                if(i>0)
                {
                this.Text="成功";
                }
                else
                {
                this.Text="失败";
                }
            }

            private void button2_Click(object sender, EventArgs e)
            {
                //声明集合
                List<tbusers> list= new List<tbusers>();
                string sql="select loginid,loginpwd from tbusers";
                using (SqlDataReader reader = SqlHelper.ExecuteReader(sql))
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            //添加到数据模型
                            tbusers model = new tbusers();
                            model.loginid = reader.GetString(0);
                            model.loginpwd = reader.GetString(1);

                            //把数据添加到集合里
                            list.Add(model);
                        }
                    }
                }
                //将集合的数据绑定到dataGridView控件
                dataGridView1.DataSource = list;
            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }
        }
    }

  • 相关阅读:
    virtualbox+vagrant学习-2(command cli)-19-vagrant box命令
    virtualbox+vagrant学习-2(command cli)-24-Aliases别名
    virtualbox+vagrant学习-2(command cli)-23-vagrant version命令
    virtualbox+vagrant学习-2(command cli)-22-vagrant validate命令
    如何快速学习一门技术或进入一个岗位
    EL表达式详解
    关于JSP乱码问题
    java mail使用qq邮箱发邮件的配置方法
    数据库命名规范
    java中的Serializable接口的作用
  • 原文地址:https://www.cnblogs.com/HarryChis/p/10368758.html
Copyright © 2011-2022 走看看