https://github.com/doobcontrol/xydb
Definition of general database operation interface and implementation of specific database operations for each database
https://github.com/doobcontrol/xydb
database mysql postresql sqlite sqlserver
Last synced: 4 months ago
JSON representation
Definition of general database operation interface and implementation of specific database operations for each database
- Host: GitHub
- URL: https://github.com/doobcontrol/xydb
- Owner: doobcontrol
- License: mit
- Created: 2023-11-14T13:07:53.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-17T15:47:37.000Z (about 1 year ago)
- Last Synced: 2025-10-11T03:39:03.033Z (9 months ago)
- Topics: database, mysql, postresql, sqlite, sqlserver
- Language: C#
- Homepage:
- Size: 572 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# xyDb
Definition of general database operation interface and implementation of specific database operations for each database
Currently includes: SQLite64, PostgreSQL, SqlServer, MySql
## Sample
Please read code details in project xyDbSample.
### Create DbService
IDbAccess dbAccess = new SQLite64DbAccess();
//IDbAccess dbAccess = new PostgreSQLDbAccess();
//IDbAccess dbAccess = new SQLServerDbAccess();
string ConnectionString = @"Data Source=testDb;";
//string ConnectionString = @"Server=localhost;Database=testdb;User Id=testuser;Password=testPassword;";
//string ConnectionString = @"Server=localhost\\SQLEXPRESS;uid=testUser;pwd=testPassword;database=testDb;Packet Size=8192;Max Pool Size=1000;Connect Timeout=30;";
DbService = new DbService(ConnectionString, dbAccess);
await DbService.openAsync();
### New record and query
maxId++;
string sql = "INSERT INTO COMPANY(ID, NAME, AGE) " + "VALUES(" + maxId + ", '', 0)";
await dbService.exeSqlAsync(sql);
sql = "SELECT * From COMPANY WHERE ID=" + maxId;
DataTable dt = await dbService.exeSqlForDataSetAsync(sql);
int i = dataGridView1.Rows.Add(dt.Rows[0].ItemArray);
dataGridView1.Rows[i].Tag = dt.Rows[0];
### Edit record
string colName = dataGridView1.Columns[e.ColumnIndex].Name;
string cellValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
string rowID = dataGridView1.Rows[e.RowIndex].Cells["ID"].Value.ToString();
string sql = "UPDATE COMPANY SET " + colName + "='" + cellValue + "' " + " WHERE ID=" + rowID;
await dbService.exeSqlAsync(sql);
### Delete record
int rowIndex = dataGridView1.SelectedRows[0].Index;
int rowID = Convert.ToInt32(dataGridView1.Rows[rowIndex].Cells["ID"].Value);
string sql = "DELETE FROM COMPANY " + " WHERE ID=" + rowID;
await dbService.exeSqlAsync(sql);
dataGridView1.Rows.RemoveAt(rowIndex);