意甲

SQL Server单引号两种处理技巧(2)_a

2020-01-16 19:59:29来源:励志吧0次阅读

程序如下: 首先把前面的函数加入。在窗体的通用中声明如下变量: Dim cnn1 As ADODB.Connection '连接Dim mycommand As ADODB.Command '命令Dim rstByQuery As ADODB.Recordset '结果集Dim strCnn As String '连接字符串Private Sub Form_Load()Set cnn1 = New ADODB.Connection '生成一个连接strCnn = "driver={SQL Server};" & _"server=ZYX_pc;uid=sa;pwd=PCDC;database=pubs" '没有系统数据源使用连接字符串'strCnn = "DSN=mydsn;UID=sa;PWD=;"'DATABASE=pubs;Driver={SQL Server};SERVER=gzl_pc" '如果系统数据源MYDSN指向PUBS数据库,也可以这样用cnn1.Open strCnn, , , 0 '打开连接End SubPrivate Sub Command1_Click() '演示字符处理Dim i As IntegerDim j As IntegerSet parm = New ADODB.ParameterSet mycommand = New ADODB.CommandDim str As Stringstr = Combo1.Textstr = ProcessStr (str)mycommand.ActiveConnection = cnn1 '指定该command 的当前活动连接mycommand.CommandText = " select * fromemployee where fname = '" & str & "'"mycommand.CommandType = adCmdText '表明command 类型Set rstByQuery = New ADODB.RecordsetSet rstByQuery = mycommand.Execute()i = 0Do While Not rstByQuery.EOFi = i + 1 ' i 中保存记录个数rstByQuery.MoveNextLoopMSFlexGrid1.Rows = i + 1 '动态设置MSFlexGrid的行和列MSFlexGrid1.Cols = rstByQuery.Fields.count + 1MSFlexGrid1.Row = 0For i = 0 To rstByQuery.Fields.count - 1MSFlexGrid1.Col = i + 1MSFlexGrid1.Text = rstByQuery.Fields.Item(i).NameNext '设置第一行的标题,用域名填充i = 0'Set rstByQuery = mycommand.Execute()rstByQuery.RequeryDo While Not rstByQuery.EOFi = i + 1MSFlexGrid1.Row = i '确定行For j = 0 To rstByQuery.Fields.count - 1MSFlexGrid1.Col = j + 1MSFlexGrid1.Text = rstByQuery(j) '添充所有的列NextrstByQuery.MoveNextLoop '这个循环用来填充MSFlexGrid的内容End SubPrivate Sub Command2_Click()'参数方法Dim i As IntegerDim j As IntegerSet parm = New ADODB.ParameterSet mycommand = New ADODB.Command' parm_jobid.Name = "name1" this line can be ommitedparm.Type = adChar '参数类型parm.Size = 10 '参数长度parm.Direction = adParamInput '参数方向,输入或输出parm.Value = Combo1.Text '参数的值mycommand.Parameters.Append parm '加入参数mycommand.ActiveConnection = cnn1 '指定该command 的当前活动连接mycommand.CommandText = " select *from employee where fname =? "mycommand.CommandType = adCmdText '表明command 类型Set rstByQuery = New ADODB.RecordsetSet rstByQuery = mycommand.Execute()i = 0Do While Not rstByQuery.EOFi = i + 1 ' i 中保存记录个数rstByQuery.MoveNextLoopMSFlexGrid1.Rows = i + 1 '动态设置MSFlexGrid的行和列MSFlexGrid1.Cols = rstByQuery.Fields.count + 1MSFlexGrid1.Row = 0For i = 0 To rstByQuery.Fields.count - 1MSFlexGrid1.Col = i + 1MSFlexGrid1.Text = rstByQuery.Fields.Item(i).NameNext '设置第一行的标题,用域名填充i = 0rstByQuery.RequeryDo While Not rstByQuery.EOFi = i + 1MSFlexGrid1.Row = i '确定行For j = 0 To rstByQuery.Fields.count - 1MSFlexGrid1.Col = j + 1MSFlexGrid1.Text = rstByQuery(j) '添充所有的列NextrstByQuery.MoveNextLoop '这个循环用来填充MSFlexGrid的内容End Sub

查询部分可以用存储过程以提高处理效率,减低网络流量。本程序在NT WORKSTATION 4.0 SP4、SQL SERVER 7.0 上调试通过。

老是口腔溃疡怎么办
孩子早上咳嗽有痰咳不出怎么办
小儿积食什么原因
治疗腹胀的中药
分享到: