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)
{
}
}
}