-
大小: 319KB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2021-06-02
- 語言: C#
- 標(biāo)簽: C#??數(shù)據(jù)庫??
資源簡(jiǎn)介
本系統(tǒng)實(shí)現(xiàn)C#對(duì)數(shù)據(jù)庫的基本操作,包括連接數(shù)據(jù)庫、增、刪、改、查的功能,并附說明文檔,還有代碼的詳細(xì)注釋,歡迎下載使用,如有疑問,請(qǐng)發(fā)信息到1726234822@qq.com,我將隨時(shí)解決問題。

代碼片段和文件信息
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?數(shù)據(jù)庫操作
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????//數(shù)據(jù)庫查詢函數(shù)
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????//清空下拉列表
????????????comboBox1.Items.Clear();
????????????comboBox2.Items.Clear();
????????????//數(shù)據(jù)庫連接參數(shù),Data?Source為服務(wù)器名稱,值為在SQL?Server中連接數(shù)據(jù)庫時(shí)的服務(wù)器名稱,Catalog為要連接的數(shù)據(jù)庫名稱,一般為自己創(chuàng)建的數(shù)據(jù)庫,第三個(gè)參數(shù)默認(rèn)
????????????string?strcon?=?“Data?Source=(local);Initial?Catalog=database;Integrated?Security=True“;
????????????//連接數(shù)據(jù)庫
????????????SqlConnection?con?=?new?SqlConnection(strcon);
????????????con.Open();
????????????//查詢SQL語句,from后為表名稱
????????????string?strSQL?=?“select?*?from?學(xué)生表“;
????????????//查詢
????????????SqlCommand?cmd?=?new?SqlCommand(strSQLcon);
????????????//返回查詢結(jié)果
????????????DataSet?ds?=?new?DataSet();
????????????SqlDataAdapter?sda?=?new?SqlDataAdapter();
????????????sda.SelectCommand?=?cmd;
????????????sda.Fill(ds“stu“);
????????????//將查詢結(jié)果數(shù)據(jù)綁定到dataGridView控件中
????????????dataGridView1.DataSource?=?ds.Tables[0];
????????????//將表中的值無重復(fù)的加入下拉列表combobox中,供修改使用
????????????for?(int?i?=?0;?i?????????????{
????????????????if?(!comboBox1.Items.Contains(dataGridView1.Rows[i].Cells[0].Value))
????????????????{
????????????????????comboBox1.Items.Add(dataGridView1.Rows[i].Cells[0].Value);
????????????????}
????????????????if?(!comboBox2.Items.Contains(dataGridView1.Rows[i].Cells[1].Value))
????????????????{
????????????????????comboBox2.Items.Add(dataGridView1.Rows[i].Cells[1].Value);
????????????????}
????????????}
????????}
????????//數(shù)據(jù)庫增加數(shù)據(jù)函數(shù)
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????//連接數(shù)據(jù)庫同上
????????????string?strcon?=?“Data?Source=(local);Initial?Catalog=database;Integrated?Security=True“;
????????????SqlConnection?con?=?new?SqlConnection(strcon);
????????????con.Open();
????????????//讀取文本框中的值,作為插入值
????????????string?strXueHao?=?textBox1.Text;
????????????string?strXingMing?=?textBox2.Text;
????????????//插入功能的SQL語句
????????????string?strSQL?=?“insert?into?學(xué)生表(學(xué)號(hào)姓名)?values(‘“+strXueHao+“‘‘“+strXingMing+“‘)“;
????????????//執(zhí)行插入操作
????????????SqlCommand?cmd?=?new?SqlCommand(strSQLcon);
????????????cmd.ExecuteNonQuery();
????????}
????????//數(shù)據(jù)庫修改數(shù)據(jù)函數(shù)
????????private?void?button3_Click(object?sender?EventArgs?e)
????????{
????????????//連接數(shù)據(jù)庫同上
????????????string?strcon?=?“Data?Source=(local);Initial?Catalog=database;Integrated?Security=True“;
????????????SqlConnection?con?=?new?SqlConnection(strcon);
????????????con.Open();
????????????//讀取下拉列表的值作為修改前數(shù)據(jù),讀取文本框的值作為要修改后的值
????????????string?strXueHao?=?textBox3.Text;
????????????string?strXingMin
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-12-08?21:20??C#操作數(shù)據(jù)庫(附說明文檔)\
?????文件??????273197??2016-12-08?21:14??C#操作數(shù)據(jù)庫(附說明文檔)\C#數(shù)據(jù)庫操作說明文檔.docx
?????目錄???????????0??2016-12-08?16:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\
?????目錄???????????0??2016-12-08?21:18??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\
?????文件????????8263??2016-12-08?21:18??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Form1.Designer.cs
?????文件????????4669??2016-12-08?21:18??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Form1.cs
?????文件????????5817??2016-12-08?21:18??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Form1.resx
?????文件?????????496??2016-12-08?21:18??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Program.cs
?????目錄???????????0??2016-12-08?16:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Properties\
?????文件????????1362??2016-12-08?16:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Properties\AssemblyInfo.cs
?????文件????????2882??2016-12-08?16:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Properties\Resources.Designer.cs
?????文件????????5612??2016-12-08?16:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Properties\Resources.resx
?????文件????????1102??2016-12-08?16:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Properties\Settings.Designer.cs
?????文件?????????249??2016-12-08?16:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\Properties\Settings.settings
?????目錄???????????0??2016-12-08?21:16??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\bin\
?????目錄???????????0??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\bin\Debug\
?????文件???????12288??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\bin\Debug\數(shù)據(jù)庫操作.exe
?????文件???????32256??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\bin\Debug\數(shù)據(jù)庫操作.pdb
?????文件???????11600??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\bin\Debug\數(shù)據(jù)庫操作.vshost.exe
?????目錄???????????0??2016-12-08?21:20??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\bin\Release\
?????目錄???????????0??2016-12-08?16:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\
?????目錄???????????0??2016-12-08?16:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\
?????目錄???????????0??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\Debug\
?????文件????????5420??2016-12-08?18:10??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6383??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????目錄???????????0??2016-12-08?21:20??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\Debug\TempPE\
?????文件?????????180??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\Debug\數(shù)據(jù)庫操作.Form1.resources
?????文件?????????180??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\Debug\數(shù)據(jù)庫操作.Properties.Resources.resources
?????文件?????????890??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\Debug\數(shù)據(jù)庫操作.csproj.FileListAbsolute.txt
?????文件????????1043??2016-12-08?21:19??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\Debug\數(shù)據(jù)庫操作.csproj.GenerateResource.Cache
?????文件????????9174??2016-12-08?18:15??C#操作數(shù)據(jù)庫(附說明文檔)\數(shù)據(jù)庫操作\數(shù)據(jù)庫操作\obj\x86\Debug\數(shù)據(jù)庫操作.csprojResolveAssemblyReference.cache
............此處省略5個(gè)文件信息
評(píng)論
共有 條評(píng)論