您的位置:首页 > 编程语言

图书检索的简单编程

2012-05-15 12:23 99 查看
直接上代码:

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 LibrarySystem

{

public partial class BookSearch : Form

{

public BookSearch() {

InitializeComponent(); }

SqlConnection Login_conn = new SqlConnection();

SqlDataAdapter Login_da;

DataTable Login_dt = new DataTable();

int RowPosition = 0;

string str;

private void Form1_Load(object sender, EventArgs e)

{

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

this.Login_conn.Close();

this.Login_conn.Dispose();

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

{

}

private void BookSearch_Load(object sender, EventArgs e) {

Login_conn.ConnectionString = "server=localhost\\sqlexpress;database=db_LibraryMS;integrated security=true";

Login_conn.Open();// TODO: 这行代码将数据加载到表“db_LibraryMSDataSet.tb_bookinfo”中。您可以根据需要移动或删除它。

this.tb_bookinfoTableAdapter.Fill(this.db_LibraryMSDataSet.tb_bookinfo);

}

private void button1_Click(object sender, EventArgs e) {

if(this.comboBox1.Text!=string.Empty&&this.textBox1.Text!="")

{ switch(this.comboBox1.Text)

{

case "作者": str = "select * from tb_bookinfo where author='"+this.textBox1.Text+"'";break;

case "书名": str = "select * from tb_bookinfo where bookname='" + this.textBox1.Text + "'"; break;

case "出版社": str = "select * from tb_bookinfo where pubname='" + this.textBox1.Text + "'"; break; }

Login_da = new SqlDataAdapter(str, Login_conn);

Login_dt.Clear();

Login_da.Fill(Login_dt);

this.dataGridView1.DataSource = Login_dt;

}

else

{ MessageBox.Show("请确认搜寻条件"); }

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: