三套路增刪改
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();
From:http://tw.wingwit.com/Article/program/net/201311/13294.html