因为刚转到C#,所以有比较多的不明白 还望各位大虾赐教.问题是这样的:
建立临时表C 包含id(int),Name(Varchar),AllCount(int),TopCount(int)这四个字段,然后分别插入数据1,Zong,1,1数据 那么我该怎么建表?怎么对其插入,
用到的是Nhibernate 数据库是Ms-sql2005
建立临时表C 包含id(int),Name(Varchar),AllCount(int),TopCount(int)这四个字段,然后分别插入数据1,Zong,1,1数据 那么我该怎么建表?怎么对其插入,
用到的是Nhibernate 数据库是Ms-sql2005
这样可以直接创建,不需要建表
带# 就是临时表
DataTable c = new DataTable();
c.Columns.Add(new DataColumn("id", typeof(int)));
c.Columns.Add(new DataColumn("Name", typeof(string)));
c.Columns.Add(new DataColumn("AllCount", typeof(int)));
c.Columns.Add(new DataColumn("TopCount", typeof(int)));//插入记录
DataRow dr = c.NewRow();
dr["id"]=1;
dr["Name"]="Zong";
dr["AllCount"]=1;
dr["TopCount"]=1;
c.Rows.Add(dr);
建立临时表 用DAtaTable 要怎么建呢?~``初学 不好意思 望指教
也可以创建临时表。临时表与永久表相似,但临时表存储在 tempdb 中,当不再使用时会自动删除。有本地和全局两种类型的临时表,二者在名称、可见性和可用性上均不相同。本地临时表的名称以单个数字符号 (#) 打头;它们仅对当前的用户连接是可见的;当用户从 Microsoft® SQL Server™ 2000 实例断开连接时被删除。全局临时表的名称以数学符号 (##) 打头,创建后对任何用户都是可见的,当所有引用该表的用户从 SQL Server 断开连接时被删除。例如,如果创建名为 employees 的表,则任何人只要在数据库中有使用该表的安全权限就可以使用该表,除非它已删除。如果创建名为 #employees 的本地临时表,只有您能对该表执行操作且在断开连接时该表删除。如果创建名为 ##employees 的全局临时表,数据表中的任何用户均可对该表执行操作。如果该表在您创建后没有其他用户使用,则当您断开连接时该表删除。如果该表在您创建后有其他用户使用,则 SQL Server在所有用户断开连接后删除该表。
command.CommandText=strSql;
command.ExecuteNonQuery();
这样就可以创建临时表了
不过不知道临时表是否满足你在程序中的需要
/// <summary>
/// 对临时表的操作
/// </summary>
public BusinessLib.System.vwOrgInfo m_vwOrgInfo = new BusinessLib.System.vwOrgInfo();
private WebApp.Lib.System.OrgInfo m_OrgInfoCtl = new WebApp.Lib.System.OrgInfo();
private void UpdateTemp()
{
//创建临时表
IList list = m_OrgInfoCtl.BaseQuery(typeof(BusinessLib.System.vwOrgInfo));
foreach (BusinessLib.System.vwOrgInfo item in list)
{
//取得待加入临时表的数据
m_vwOrgInfo = m_OrgInfoCtl.ItemLoadByVwID(item.OrgID); //加载当前OrgID所在行的数据
int iOrgID = m_vwOrgInfo.OrgID;
string strOrganName = m_vwOrgInfo.OrganName;
WebApp.Lib.MsgMng.MsgInfo m_MsgInfoCtl = new WebApp.Lib.MsgMng.MsgInfo(); //调用统计函数
int iAllCount = m_MsgInfoCtl.CountMsg(iOrgID, 5); //统计所有发表数量
int iTolCount = m_MsgInfoCtl.CountMsg(iOrgID, 5, true); //统计前台显示数量
//建表
DataTable c = new DataTable();
c.Columns.Add(new DataColumn("id", typeof(int)));
c.Columns.Add(new DataColumn("Name", typeof(string)));
c.Columns.Add(new DataColumn("AllCount", typeof(int)));
c.Columns.Add(new DataColumn("TopCount", typeof(int)));
//插入记录
DataRow dr = c.NewRow();
dr["id"] = iOrgID;
dr["Name"] = strOrganName;
dr["AllCount"] = iAllCount;
dr["TopCount"] = iTolCount;
c.Rows.Add(dr);
}
}
然后我是要在Page_Load中对该表进行引用绑定操作,
protected void Page_Load(object sender, EventArgs e)
{
UpdateTemp(); //调用创建该临时表
InitData(m_AspNetPager.GetAspNetPager, typeof( 临时表 ), m_Repeater);
if (!IsPostBack)
{
base.BasePageDataBinding();
base.DataBind();
}
}
c.Columns.Add(new DataColumn("id", typeof(int)));
c.Columns.Add(new DataColumn("Name", typeof(string)));
c.Columns.Add(new DataColumn("AllCount", typeof(int)));
c.Columns.Add(new DataColumn("TopCount", typeof(int)));
//插入记录
DataRow dr = c.NewRow();
dr["id"] = iOrgID;
dr["Name"] = strOrganName;
dr["AllCount"] = iAllCount;
dr["TopCount"] = iTolCount;
c.Rows.Add(dr);
这些代码我是希望建起 临时表#OrgTol 并逐行进行插入操作的
{
DataTable c = new DataTable();//创建临时表
DataTable c = new DataTable();
c.Columns.Add(new DataColumn("id", typeof(int)));
c.Columns.Add(new DataColumn("Name", typeof(string)));
c.Columns.Add(new DataColumn("AllCount", typeof(int)));
c.Columns.Add(new DataColumn("TopCount", typeof(int)));
UpdateTemp(); //在这个处理过程里面取消建表的过程,即上面的内容
//邦定临时表到Repeater控件如:
Repeater1.DataSource=c;
Repeater1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
c.Columns.Add(new DataColumn("id", typeof(int)));
c.Columns.Add(new DataColumn("Name", typeof(string)));
c.Columns.Add(new DataColumn("AllCount", typeof(int)));
c.Columns.Add(new DataColumn("TopCount", typeof(int)));
UpdateTemp(); //在这个处理过程里面取消建表的过程,即上面的内容
//邦定临时表到Repeater控件如:
Repeater1.DataSource=c;
Repeater1.DataBind();
}把创建临时表放在外面