从数据库表里查找若干条指定字段 插入到新数据表中,有什么简介的写法吗我只能靠循环了,但是不知道有没有别的简介写法
解决方案 »
- 在asp.net中怎样把汉字转换成utf字符阿? 急,急,急
- 求一个asp.net c#的根据硬盘、CPU 信息注册的示例源码。
- 新手数据库问题,高分求教!!
- ISS7.0 出现一个问题。大哥大姐帮帮小弟,小弟不行了!55555555555!
- 公测(连续3天300分)
- 不刷新 用户控件问题
- DataGrid中编辑列的更新函数,在进入编辑状态后不能取得新输入的值,怎么办?
- gridview绑定两个dropdownlist的问题,非联动
- 利用dropdownlist控件,的困惑!
- 请各位推荐几种好用的编辑工具
- asp.net上传视频并生成缩略图的代码?急急急
- 关于ie8用模板(masterpage)后的问题。。。急救。。。。。
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace winApplication
{
public class sqlAccess
{
//与SQL Server的连接字符串设置
private string _connString;
private string _strSql;
private SqlCommandBuilder sqlCmdBuilder;
private DataSet ds = new DataSet();
private SqlDataAdapter da;
public sqlAccess(string connString,string strSql)
{
this._connString=connString;
}
private SqlConnection GetConn()
{
try
{
SqlConnection Connection = new SqlConnection(this._connString);
Connection.Open();
return Connection;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"数据库连接失败");
throw;
}
}
//根据输入的SQL语句检索数据库数据
public DataSet SelectDb(string strSql,string strTableName)
{
try
{
this._strSql = strSql;
this.da = new SqlDataAdapter(this._strSql,this.GetConn());
this.ds.Clear();
this.da.Fill(ds,strTableName);
return ds;//返回填充了数据的DataSet,其中数据表以strTableName给出的字符串命名
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"数据库操作失败");
throw;
}
}
//数据库数据更新(传DataSet和DataTable的对象) public DataSet UpdateDs(DataSet changedDs,string tableName)
{
try
{
this.da = new SqlDataAdapter(this._strSql,this.GetConn());
this.sqlCmdBuilder = new SqlCommandBuilder(da);
this.da.Update(changedDs,tableName);
changedDs.AcceptChanges();
return changedDs;//返回更新了的数据库表
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"数据库更新失败");
throw;
}
}参考
Insert into Table2(field1,field2,...) select value1,value2,... from Table1
select 字段 from table into anothertable
where