c#

位置:IT落伍者 >> c# >> 浏览文章

ADO.NET增删查改小总结


发布日期:2022年05月05日
 
ADO.NET增删查改小总结

三套路增删改

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();

               

上一篇:.net编程之路(四)

下一篇:详细讲解C#的多线程能力