Home Database Mysql Tutorial 自动生成程序,免去增,删,改,查的数据库编程 ( 定义游标,逐

自动生成程序,免去增,删,改,查的数据库编程 ( 定义游标,逐

Jun 07, 2016 pm 03:35 PM
definition database cursor program programming Automatic generated

数据库编程,繁琐的增,删,改,查。 每个表都要实现,为了简化工作,可以用以下的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

 

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

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 iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

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

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How does Go WebSocket integrate with databases?

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

How to handle database connection errors in PHP

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

How to use database callback functions in Golang?

The Key to Coding: Unlocking the Power of Python for Beginners The Key to Coding: Unlocking the Power of Python for Beginners Oct 11, 2024 pm 12:17 PM

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

Java Made Simple: A Beginner's Guide to Programming Power Java Made Simple: A Beginner's Guide to Programming Power Oct 11, 2024 pm 06:30 PM

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

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Oct 11, 2024 pm 08:58 PM

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

See all articles