In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to query student files in C#. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The details are as follows
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 parameter query {public partial class Form1: Form {public Form1 () {InitializeComponent ();} private SqlDataAdapter sqlDataAdapter; private DataSet dataSet Private void Form1_Load (object sender, EventArgs e) {/ / TODO: this line loads the data into the table "xsglDataSet.student". You can move or delete it as needed. / / this.studentTableAdapter.Fill (this.xsglDataSet.student); / / Sqlconnection is to establish an open connection to the sqlserver database SqlConnection myConnection = new SqlConnection (); myConnection.ConnectionString = "server=localhost;uid=sa;pwd=root;database=xsgl"; / / the SqlCommand object is used to execute operation commands on the SQL Server database. SqlCommand sqlCommand = new SqlCommand (); sqlCommand.Connection = myConnection; sqlCommand.CommandType = CommandType.Text; / / Fuzzy query sqlCommand.CommandText = "select * from student where studID like @ studID and studName like @ studName and studSex like @ studSex" / / comm.Parameters.Add () add parameters to the parameter set. The first parameter in add is the name of the parameter to be added, the second parameter is the data type of the parameter, and the third is the length. The function of Parameters is to pass the parameters obtained after the execution of the stored procedure to the program 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"); / / the following three are assigned 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 = = "") {/ / if you do not enter id sqlDataAdapter.SelectCommand.Parameters ["@ studID"] .Value = "%" } else {sqlDataAdapter.SelectCommand.Parameters ["@ studID"] .Value = textBox1.Text;} if (textBox2.Text = "") {/ / if the name sqlDataAdapter.SelectCommand.Parameters ["@ studName"] .Value = "%" is not entered } 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 = "male";} else {sqlDataAdapter.SelectCommand.Parameters ["@ studSex"] .Value = "female" } dataSet.Tables ["student"] .Clear (); sqlDataAdapter.Fill (dataSet, "student");} catch (SqlException ee) {MessageBox.Show (ee.Message);}
This is the end of the article on "how to query student files in C#". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.