源代码:
1
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 WindowsFormsApplication1
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}
String str = @"Data Source=127.0.0.1;Initial Catalog=学¡ì生¦¨²;Integrated Security=True";
SqlConnection conn = new SqlConnection();
SqlDataReader result = null;
public bool loginus(string un, string pw)
{
conn.ConnectionString = str;
string sql = "select * from user1 where username='" + un + " 'and password='" + pw + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Connection.Open();
try
{
result = cmd.ExecuteReader();
}
catch (Exception)
{
MessageBox.Show("对?不?起e!ê?查¨¦询¡¥数ºy据Y失º¡ì败㨹!ê?", "提¬¨¢示º?");
}
if (result != null)
{
if (result.Read())
{
return true;
}
}
result.Close();
cmd.Connection.Close();
return false;
}
private void button1_Click(object sender, EventArgs e)
//确¨¡¤定¡§按ã¡ä钮£¤单Ì£¤击¡Â事º?件t
{
string n = textBox1.Text.Trim();
string p = textBox2.Text.Trim();
if ((textBox1.Text != "") & (textBox2.Text != ""))
{
if (loginus(n, p) == false)
{
MessageBox.Show("用®?户¡ì或¨°密¨¹码?错䨪");
return;
}
DialogResult = DialogResult.OK;
//给?窗ä¡ã体¬?的Ì?dialogresult属º?性?赋3值¦Ì
this.Hide();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
2:
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 WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void 精?确¨¡¤查¨¦询¡¥AToolStripMenuItem_Click(object sender, EventArgs e)
{
if (comboBox1.Text == "")
{
MessageBox.Show("请?先¨¨选?择?查¨¦询¡¥方¤?式º?!ê?", "提¬¨¢示º?");
}
else
{
string aa = @"Data Source=127.0.0.1;Initial Catalog=学¡ì生¦¨²;Integrated Security=True";
SqlConnection sqlConnection1 = new SqlConnection();
sqlConnection1.ConnectionString = aa; //设¦¨¨置?连¢?接¨®字Á?符¤?串ä?
string sql = "select * from hyt2008 where " + comboBox1.Text + "='" + textBox1.Text + "'";
SqlCommand sqlCommand1 = new SqlCommand();
sqlCommand1.CommandText = sql;
sqlCommand1.Connection = sqlConnection1;
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConnection1);
DataSet ds = new DataSet();
try
{
sqlConnection1.Open();
da.Fill(ds);
}
catch (Exception)
{
MessageBox.Show("对?不?起e!ê?精?确¨¡¤查¨¦找¨°失º¡ì败㨹!ê?", "提¬¨¢示º?");
}
finally
{
sqlConnection1.Close();
}
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
}
private void 模¡ê糊y查¨¦询¡¥BToolStripMenuItem_Click(object sender, EventArgs e)
{
if (comboBox1.Text == "")
{
MessageBox.Show("请?先¨¨选?择?查¨¦询¡¥方¤?式º?!ê?", "提¬¨¢示º?");
}
else
{
string aa = @"Data Source=127.0.0.1;Initial Catalog=学¡ì生¦¨²;Integrated Security=True";
SqlConnection sqlConnection1 = new SqlConnection();
sqlConnection1.ConnectionString = aa; //设¦¨¨置?连¢?接¨®字Á?符¤?串ä?
string sql = "select * from hyt2008 where" + comboBox1.Text + "like'" + textBox1.Text + "%'";
SqlCommand sqlCommand1 = new SqlCommand();
sqlCommand1.CommandText = sql;
sqlCommand1.Connection = sqlConnection1;
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConnection1);
DataSet ds = new DataSet();
try
{
sqlConnection1.Open();
da.Fill(ds);
}
catch (Exception)
{
MessageBox.Show("对?不?起e!ê?模¡ê糊y查¨¦找¨°失º¡ì败㨹!ê?", "提¬¨¢示º?");
}
finally
{
sqlConnection1.Close();
}
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
}
private void 添¬¨ª加¨®HToolStripMenuItem_Click(object sender, EventArgs e)
{
string aa = @"Data Source=127.0.0.1;Initial Catalog=学¡ì生¦¨²;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = aa; //设¦¨¨置?连¢?接¨®字Á?符¤?串ä?
string cmdText = @"insert into hyt2008(拼¡ä音°?检¨¬索¡Â,汉o字Á?检¨¬索¡Â,备À?注Á¡é)values('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
SqlCommand cmd = new SqlCommand(cmdText, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
qingkong();
}
catch (Exception)
{
MessageBox.Show("对?不?起e!ê?添¬¨ª加¨®数ºy据Y失º¡ì败㨹!ê?", "提¬¨¢示º?");
}
finally
{
con.Close();
}
shuaxin();
}
void qingkong()
{
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
void shuaxin()
{
string aa = @"Data Source=127.0.0.1;Initial Catalog=学¡ì生¦¨²;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = aa; //设¦¨¨置?连¢?接¨®字Á?符¤?串ä?
string cmdText = "select * from hyt2008";
SqlDataAdapter da = new SqlDataAdapter(cmdText, con);
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds);
}
catch (Exception)
{
MessageBox.Show("对?不?起e!ê?精?确¨¡¤查¨¦找¨°失º¡ì败㨹!ê?", "提¬¨¢示º?");
}
finally
{
con.Close();
}
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
private void 删¦?除yJToolStripMenuItem_Click(object sender, EventArgs e)
{
string aa = @"Data Source=127.0.0.1;Initial Catalog=学¡ì生¦¨²;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = aa; //设¦¨¨置?连¢?接¨®字Á?符¤?串ä?
MessageBox.Show("删¦?除y前¡ã请?查¨¦询¡¥");
if (comboBox1.Text == "")
{
MessageBox.Show("请?先¨¨输º?入¨?删¦?除y的Ì?类¤¨¤型¨ª");
}
else
{
string cmdText = "delete hyt2008 where " + comboBox1.Text + "='" + textBox1.Text + "'";
SqlCommand cmd = new SqlCommand(cmdText, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
qingkong();
}
catch (Exception)
{
MessageBox.Show("对?不?起e!ê?删¦?除y数ºy据Y失º¡ì败㨹!ê?", "提¬¨¢示º?");
}
finally
{
con.Close();
}
shuaxin();
}
}
private void 退ª?出?EToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void 修T改?KToolStripMenuItem_Click(object sender, EventArgs e)
{
string aa = @"Data Source=127.0.0.1;Initial Catalog=学¡ì生¦¨²;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = aa; //设¦¨¨置?连¢?接¨®字Á?符¤?串ä?
MessageBox.Show("修T改?前¡ã请?查¨¦询¡¥");
if (comboBox1.Text == "")
{
MessageBox.Show("请?先¨¨输º?入¨?修T改?的Ì?类¤¨¤型¨ª");
}
else
{
string cmdText = "update hyt2008 set 备À?注Á¡é='" + textBox4.Text + "' where " + comboBox1.Text + "='" + textBox1.Text + "'";
SqlCommand cmd = new SqlCommand(cmdText, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
qingkong();
}
catch (Exception)
{
MessageBox.Show("对?不?起e!ê?修T改?数ºy据Y失º¡ì败㨹!ê?", "提¬¨¢示º?");
}
finally
{
con.Close();
}
shuaxin();
}
}
}
}
实验结果:
实验报告学院系名称计算机与通信工程学院第1页共9页第2页共9页第3页共9页第4页共9页第5页共9页第6页共9页第7页共9页第8页共…
实验一环境配置与sql操作学号姓名日期20xx年11月251实验目的熟悉VS20xx开发环境复习C和SQL20xx相关操作2实验环…
NET上机实验报告WEB数据库应用程序设计姓名杨森班级计103学号10101020xx2实验成绩一实验目的通过对aspnet学习完…
燕山大学Net程序设计实验报告学院信息科学与工程学院年级专业08级计算机科学2班指导教师崔永强学生学号080104010108学生…
河南城建学院网站建设技术实验报告实验名称用户名密码登录切图制作网站专业班级软件工程姓名吴春龙学号084413147实验日期20xx…
20xx13137028陈旻实计科1301ASPNET网站开发实验指导老师柯鹏学院计算机学院学生姓名陈旻实学生学号20xx1313…
实验一1实验要求基本的网页制作2目的掌握HTML与ASPX基础联系制作基本的ASPNET网页使用VS20xx提供的导航控件并结合站…
实验一环境配置与sql操作学号姓名日期1实验目的熟悉VS20xx开发环境复习C和SQL20xx相关操作2实验环境WindowsXP…
燕山大学Net程序设计实验报告学院信息科学与工程学院年级专业09级信息安全1班指导教师崔永强学生学号090104070017学生姓…
丽水职业技术学院机电信息分院课程实训基于ASP.NET旅游导购网站的设计与开发学生学号:学生姓名:实训老师:班级信管1222专业名…