欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)學(xué)生檔案查詢

 更新時(shí)間:2022年01月19日 08:54:36   作者:安靜點(diǎn)DGC  
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)學(xué)生檔案查詢,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C#實(shí)現(xiàn)學(xué)生檔案查詢的具體代碼,供大家參考,具體內(nèi)容如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 參數(shù)查詢
{
? ? public partial class Form1 : Form
? ? {
? ? ? ? public Form1()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? }
? ? ? ? private SqlDataAdapter sqlDataAdapter;
? ? ? ? private DataSet dataSet;
? ? ? ? private void Form1_Load(object sender, EventArgs e)
? ? ? ? {
?
? ? ? ? ? ? // TODO: ?這行代碼將數(shù)據(jù)加載到表“xsglDataSet.student”中。您可以根據(jù)需要移動(dòng)或刪除它。
? ? ? ? ?// ? this.studentTableAdapter.Fill(this.xsglDataSet.student);
? ? ? ? ? ? //Sqlconnection就是建立到sqlserver數(shù)據(jù)庫(kù)的打開(kāi)的連接
? ? ? ? ? ? SqlConnection myConnection = new SqlConnection();
? ? ? ? ? ? myConnection.ConnectionString = "server=localhost;uid=sa;pwd=root;database=xsgl";
? ? ? ? ? ? // SqlCommand對(duì)象用來(lái)對(duì)SQL Server數(shù)據(jù)庫(kù)執(zhí)行操作命令。
? ? ? ? ? ? SqlCommand sqlCommand = new SqlCommand();
? ? ? ? ? ? sqlCommand.Connection = myConnection;
? ? ? ? ? ? ? sqlCommand.CommandType = CommandType.Text;
? ? ? ? ? ? //模糊查詢
? ? ? ? ? ? ? sqlCommand.CommandText = "select * from student where studID like @studID and studName like @studName and studSex like @studSex";
? ? ? ? ? ? //comm.Parameters.Add()添加參數(shù)到參數(shù)集,add里面的第一個(gè)參數(shù)是要添加的參數(shù)名,第二個(gè)參數(shù)是參數(shù)的數(shù)據(jù)類型,第三個(gè)是長(zhǎng)度 ,Parameters的作用就是把存儲(chǔ)過(guò)程執(zhí)行結(jié)束后得到的參數(shù)傳到程序里
?
? ? ? ? ? ? sqlCommand.Parameters.Add("@studID",System.Data.SqlDbType.VarChar,10,"studID");
? ? ? ? ? ? sqlCommand.Parameters.Add("@studName", System.Data.SqlDbType.VarChar, 10, "studName");
? ? ? ? ? ? sqlCommand.Parameters.Add("@studSex", System.Data.SqlDbType.VarChar, 2, "studSex");
? ? ? ? ? ? //下面的三個(gè)是賦值
? ? ? ? ? ? sqlCommand.Parameters["@studID"].Value = "%";
? ? ? ? ? ? sqlCommand.Parameters["@studName"].Value = "%";
? ? ? ? ? ? sqlCommand.Parameters["@studSex"].Value = "%";
?
? ? ? ? ? ? sqlDataAdapter = new SqlDataAdapter();
? ? ? ? ? ? dataSet = new DataSet();
? ? ? ? ? ? sqlDataAdapter.SelectCommand = sqlCommand;
? ? ? ? ? ? sqlDataAdapter.Fill(dataSet,"student");
? ? ? ? ? dataGridView1.DataSource = dataSet;
? ? ? ? ? ? dataGridView1.DataMember = "student";
?
? ? ? ? }
?
? ? ? ? private void button1_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? if (textBox1.Text == "")
? ? ? ? ? ? ? ? {//如果沒(méi)有輸入id
? ? ? ? ? ? ? ? ? ? sqlDataAdapter.SelectCommand.Parameters["@studID"].Value = "%";
?
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else {
? ? ? ? ? ? ? ? ? ? sqlDataAdapter.SelectCommand.Parameters["@studID"].Value = textBox1.Text;
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? }
?
?
? ? ? ? ? ? ? ? if (textBox2.Text == "")
? ? ? ? ? ? ? ? {//如果沒(méi)有輸入姓名
? ? ? ? ? ? ? ? ? ? sqlDataAdapter.SelectCommand.Parameters["@studName"].Value = "%";
?
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? sqlDataAdapter.SelectCommand.Parameters["@studName"].Value = textBox2.Text;
?
? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? //
? ? ? ? ? ? ? ? if (comboBox1.SelectedIndex == 0) {
?
? ? ? ? ? ? ? ? ? ? sqlDataAdapter.SelectCommand.Parameters["@studSex"].Value = "%";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else if (comboBox1.SelectedIndex == 1)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? sqlDataAdapter.SelectCommand.Parameters["@studSex"].Value = "男";
?
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else {
? ? ? ? ? ? ? ? ? ? sqlDataAdapter.SelectCommand.Parameters["@studSex"].Value = "女";
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? dataSet.Tables["student"].Clear();
? ? ? ? ? ? ? ? sqlDataAdapter.Fill(dataSet,"student");
?
? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ? ? catch (SqlException ee) { MessageBox.Show(ee.Message); }
?
?
? ? ? ? }
? ? }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論