三套路增删改
Code
using SystemDataSqlClient;
SqlConnection conn = new SqlConnection(xxx);
string sql = xxx;
SqlCommand comm = new SqlCommand(sql conn);
connOpen();
commExecuteNonQuery();
connClose();
三套路查(绑定到DataGridView
Code
using SystemDataSqlClient;
SqlConnection conn = new SqlConnection(xxx);
string sql = xxx;
SqlDataAdapter da = new SqlDataAdapter(sql conn);
DataSet ds = new DataSet();
daFill(ds);
dataGridViewDataSource = dsTables[];
//要更新 查询语句要 查询主键列
SqlCommandBuilder sd = new SqlCommandBuilder(da);
daUpdate(dsTables[]);
三套路查(绑定到ListView)
代码
using SystemDataSqlClient;
SqlConnection conn = new SqlConnection(xxx);
string sql = xx;
SqlCommand comm = new SqlCommand(sql conn);
connOpen();
SqlDataReader read = commExecuteReader();
while (readRead())
{
ListViewItem lvi = new ListViewItem(read[xxx]ToString());
lviTag = read[id];
listViewItemsAdd(lvi);
lviSubItemsAddRange(new String[] { read[xxx]ToString() });
}
readClose();
connClose();