-
大小: 503KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-05-07
- 語言: C#
- 標簽: C#??SQLite??datagridview??
資源簡介
本人是初學者,本例程也只適合C#和SQLite的初學者。重點介紹SQLite的使用,通過編寫Helper.cs文件簡化SQLite的代碼編寫。在完成對數據庫的添刪改查的同時,對DataGridView控件進行深入挖掘編程。

代碼片段和文件信息
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;
namespace?學生成績管理
{
????public?partial?class?MainForm?:?Form
????{
????????#region?公用成員變量
????????studinfo?stud_info?=?new?studinfo();
????????private?string?commandText?=?““;
????????private?static?string?DBName?=?“jianxuxie.db“;
????????private?static?string?datasource?=?System.AppDomain.CurrentDomain.baseDirectory?+?DBName;
????????private?static?string?connectionString?=?@“Data?Source=“?+?datasource;
????????DBHelper?dbHelper?=?new?DBHelper(connectionString);
????????#endregion
????????public?MainForm()
????????{
????????????InitializeComponent();
????????????this.InitializeDatabase();
????????????this.LoadTable(dataGridView1?“table_stud_info“);
????????}
????????#region?自定義函數
????????private?void?InitializeDatabase()
????????{
????????????//創建數據庫
????????????dbHelper.CreateNewDatabase(DBName);
????????????//?數據庫中創建表?
????????????commandText?=?“create?table?if?not?exists?table_stud_info(學號?varchar(10)?primary?key姓名?varchar(6)高數?float物理?floatC語言?float外語?float德育?float平均?float及格?varchar(1))“;
????????????dbHelper.CreateTable(commandText);
????????}
????????private?string?Get_Column_Max_add_one(string?ColumnName)
????????{
????????????int?k?=?0;
????????????int?j?=?0;
????????????string?result?=?““;
????????????for?(int?i?=?0;?i?????????????{
????????????????if?(i?==?0)?k?=?Convert.ToInt32(dataGridView1.Rows[i].Cells[ColumnName].Value);
????????????????if?(k?????????????????{
????????????????????k?=?Convert.ToInt32(dataGridView1.Rows[i].Cells[ColumnName].Value);
????????????????????j?=?i;
????????????????}
????????????}
????????????if?(j?==?0)
????????????{
????????????????result?=?“1“;
????????????}?
????????????else
????????????{
????????????????result?=?(Convert.ToInt32(dataGridView1.Rows[j].Cells[ColumnName].Value)?+?1).ToString();
????????????????for?(int?i?=?result.Length;?i?????????????????????result?=?“0“?+?result;
????????????}
????????????return?result;
????????}
????????private?void?Delete_Row()
????????{
????????????DialogResult?dr?=?MessageBox.Show(“確定要刪除嗎?“?“提示“?MessageBoxButtons.OKCancel?MessageBoxIcon.Question);
????????????if?(dr?==?DialogResult.OK)
????????????{
????????????????commandText?=?“DELETE?FROM?table_stud_info?WHERE?學號?=?‘“?+?tb_del_xuehao.Text.Trim()?+?“‘“;
????????????????dbHelper.DeleteFromTable(commandText);
????????????}
????????????this.LoadTable(dataGridView1?“table_stud_info“);
????????}
????????private?void?set_tabpage_from_datagridview()
????????{
????????????if?(dataGridView1.CurrentCellAddress.X?>=?0?&&?dataGridView1.CurrentCellAddress.Y?>=?0)
?????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3072??2016-12-26?20:34??學生成績管理\學生成績管理\bin\Debug\jianxuxie.db
?????文件?????960000??2013-08-07?13:09??學生成績管理\學生成績管理\bin\Debug\System.Data.SQLite.dll
?????文件??????48640??2016-12-26?20:31??學生成績管理\學生成績管理\bin\Debug\學生成績管理.exe
?????文件??????56832??2016-12-26?20:31??學生成績管理\學生成績管理\bin\Debug\學生成績管理.pdb
?????文件??????11600??2016-12-26?20:34??學生成績管理\學生成績管理\bin\Debug\學生成績管理.vshost.exe
?????文件??????11600??2016-12-26?20:31??學生成績管理\學生成績管理\bin\Release\學生成績管理.vshost.exe
?????文件????????490??2010-03-17?22:39??學生成績管理\學生成績管理\bin\Release\學生成績管理.vshost.exe.manifest
?????文件??????31654??2016-12-26?16:24??學生成績管理\學生成績管理\MainForm.cs
?????文件??????72200??2016-12-25?23:54??學生成績管理\學生成績管理\MainForm.Designer.cs
?????文件???????9274??2016-12-25?23:54??學生成績管理\學生成績管理\MainForm.resx
?????文件???????6410??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????522??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件????????474??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件??????11990??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Debug\ResolveAssemblyReference.cache
?????文件????????838??2016-12-26?20:34??學生成績管理\學生成績管理\obj\x86\Debug\學生成績管理.csproj.FileListAbsolute.txt
?????文件??????48640??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Debug\學生成績管理.exe
?????文件???????2568??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Debug\學生成績管理.MainForm.resources
?????文件??????56832??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Debug\學生成績管理.pdb
?????文件????????180??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Debug\學生成績管理.Properties.Resources.resources
?????文件???????2164??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Release\DesignTimeResolveAssemblyReferences.cache
?????文件???????6415??2016-12-26?20:31??學生成績管理\學生成績管理\obj\x86\Release\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????502??2016-12-19?21:13??學生成績管理\學生成績管理\Program.cs
?????文件???????1386??2016-12-19?20:19??學生成績管理\學生成績管理\Properties\AssemblyInfo.cs
?????文件???????2884??2016-12-19?20:19??學生成績管理\學生成績管理\Properties\Resources.Designer.cs
?????文件???????5612??2016-12-19?20:19??學生成績管理\學生成績管理\Properties\Resources.resx
?????文件???????1101??2016-12-19?20:19??學生成績管理\學生成績管理\Properties\Settings.Designer.cs
?????文件????????249??2016-12-19?20:19??學生成績管理\學生成績管理\Properties\Settings.settings
?????文件??????10969??2016-12-20?09:27??學生成績管理\學生成績管理\SQLiteHelper.cs
?????文件????????430??2016-12-20?21:50??學生成績管理\學生成績管理\studinfo.cs
?????文件???????4060??2016-12-20?11:29??學生成績管理\學生成績管理\學生成績管理.csproj
............此處省略17個文件信息
評論
共有 條評論