📄 mydatabase.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace TestComponent
{
public class MyDataBase
{
//返回表中记录数
public int GetRecordCount(string connString, string tableName)
{
int number = -1;
SqlConnection conn = new SqlConnection(connString);
SqlCommand command = new SqlCommand("select count(*) from " + tableName, conn);
try
{
conn.Open();
number = (int)command.ExecuteScalar();
conn.Close();
}
catch (Exception err)
{
throw new Exception(err.Message);
}
return number;
}
//根据Select语句自动生成其他SQL语句
public void BuildAdapter(ref SqlDataAdapter adapter)
{
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
adapter.DeleteCommand = builder.GetDeleteCommand();
adapter.InsertCommand = builder.GetInsertCommand();
adapter.UpdateCommand = builder.GetUpdateCommand();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -