练习点:
数据库读取数据并保存在一个集合中.
使用DataGridView来显示数据.
1 Form1 用于用户登录验证
Form1 Code
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;
namespace DataGridViewTest2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string username = txtUsername.Text;
string password = txtPassword.Text;
DBConnect dbc = new DBConnect();
int s = dbc.UserLogin(username, password);
if (1 == s)
{
MessageBox.Show("Incorrect Username");
}
if (2 == s)
{
MessageBox.Show("Incorrect Password");
}
if(0 == s)
{
Form2 form2 = new Form2(this);
//this.Hide();
form2.ShowDialog();
}
}
}
}
2. Form2, 用记显示数据, 它只有一个DataGridView控件
Form2 Code
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.Collections;
namespace DataGridViewTest2
{
public partial class