WEB开发网
开发学院WEB开发ASP.NET 手动插入自增列 阅读

手动插入自增列

 2012-09-04 09:38:03 来源:WEB开发网   
核心提示: //测试插入自增列 string sqlstr = "SET IDENTITY_INSERT t1 ON;"; lists.Add(sqlstr); sqlstr = "INSERT INTO t1
 //测试插入自增列
                string sqlstr = "SET IDENTITY_INSERT t1 ON;";
                lists.Add(sqlstr);
                sqlstr = "INSERT INTO t1       (id, name) VALUES ("+i.ToString()+", '" + i.ToString()+"');";
                lists.Add(sqlstr);
                sqlstr = "set identity_insert t1 off;";
                lists.Add(sqlstr);

                da.SqlCeExecuteNonQuery(lists);
 public void SqlCeExecuteNonQuery(List<string> lists)
        {
            SqlCeConnection conn = new SqlCeConnection();
            SqlCeCommand comm = null;
            try
            {
                conn.ConnectionString = PDAConnectionLocStr;
                conn.Open();
                comm = new SqlCeCommand("", conn);
                for (int i = 0; i < lists.Count; i++)
                {
                    comm.CommandText = lists[i];
                    comm.ExecuteNonQuery();
                }



            }
            catch (SqlCeException ex)
            {
 
            }
            finally
            {
                conn.Close();
                conn.Dispose();
                comm.Dispose();
            }
        }

Tags:手动 插入

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接