自动生成程序,免去增,删,改,查的数据库编程 ( 定义游标,逐
Jun 07, 2016 pm 03:35 PM数据库编程,繁琐的增,删,改,查。 每个表都要实现,为了简化工作,可以用以下的sql批处理来输出你想要得结果。 不用一个一个列去写。 只需要提供表名称tablename,并把print部分修改成你需要的就可以了。 --请设置查询分析器以文本显示结果 --定义变量 de
数据库编程,繁琐的增,删,改,查。
每个表都要实现,为了简化工作,可以用以下的sql批处理来输出你想要得结果。
不用一个一个列去写。
只需要提供表名称tablename,并把print部分修改成你需要的就可以了。
--请设置查询分析器以文本显示结果
--定义变量
declare @tablename nvarchar(50)--表的名称
declare @tableid int --表的id
declare @colname nvarchar(50) --列名
declare @index int
--赋值
set @tablename = 'tablename' -->>>tablename改为你要查询的表名
select @tableid = id from sysobjects where id = object_id(@tablename)
set @index = 0
--定义游标,逐个遍历表的每个列
declare columns_cursor cursor
for select name as 'Column_name' from syscolumns where id = @tableid order by colid
--打开游标
open columns_cursor
fetch next from columns_cursor into @colname
while @@FETCH_STATUS = 0
begin
-->>>这句需要修改成你要的样式即可(增,删,改,查。)
--我的这句是向一个数据控件写数据(用友华表cell)
print 'axCell1.SetCellString(' + cast(@index as nvarchar) + ', j, 0, ds.Tables[0].Rows[i]["' + @colname + '"].ToString());'
set @index = @index + 1
fetch next from columns_cursor into @colname
end
--关闭,释放游标
close columns_cursor
deallocate columns_cursor

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed tutorial on establishing a database connection using MySQLi in PHP

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

How does Go WebSocket integrate with databases?

How to handle database connection errors in PHP

How to use database callback functions in Golang?

The Key to Coding: Unlocking the Power of Python for Beginners

Java Made Simple: A Beginner's Guide to Programming Power

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder
