12226.html

来自「以电子书的形式收集了VB一些常见问题解决方法,可以很方便的查找自己需要解决的问题」· HTML 代码 · 共 22 行

HTML
22
字号
<html>
  <head>
    <title>ADO &amp; NULL</title>
  </head>
  <body bgcolor="#FFFFFF" vlink="#808080">
    <center>
      <h1>ADO &amp; NULL</h1>
    </center>
<hr size=7 width=75%>

<hr size=7 width=75%><p>
Posted by <a href="mailto:ariel_cy@usa.net">Ariel</a> on April 21, 1999 at 08:46:44:<p>
I have a procedure,I hope it can access from SQL with ADO,if a value of field<br>is NULL,then it's be space,but I can only get the value first,after the first,<br>I get NULL always.Why?<p>Global cn As New ADODB.Connection<br>Global quescmd As New ADODB.Command<br>Global quesrec As New ADODB.Recordset<p>.Private Main()<br>.    Dim parm As ADODB.Parameter<br>.    Dim conn As String<br>.    <br>.    conn = "driver={SQL Server};server=ntserver1;uid=sa;pwd=;database=cbt"<br>.    With cn<br>.        .ConnectionString = conn<br>.        .ConnectionTimeout = 10<br>.        .Open<br>.    End With<br>.    <br>.    Set quescmd = New ADODB.Command<br>.    quescmd.ActiveConnection = cn<br>.    With quescmd<br>.        .CommandText = "select * from cbt_question where question_id=?"<br>.        .CommandType = adCmdText<br>.        .CommandTimeout = 15<br>.    End With<br>.    Set parm = New ADODB.Parameter<br>.    With parm<br>.        .Type = adChar<br>.        .Size = 8<br>.        .Direction = adParamInput<br>.        quescmd.Parameters.Append parm<br>.    End With<br>.End Sub<br>.<br>.Private Sub DispQues(quesid As String)<br>.    Dim i As Integer<br>.    Dim midstr As String<br>.    <br>.    quescmd.Parameters(0).Value = quesid<br>.    Set quesrec = quescmd.Execute()<br>.    <br>.    If quesrec.EOF = True Then<br>.        MsgBox "Not exist any question"<br>.        Exit Sub<br>.    End If<br>.    <br>.    QUESLABEL.Caption = quesrec!question_desc.GetChunk(200)   'All fields are Text in SQL<br>.    For i=1 To 3<br>.      if IsNull(quesrec.fields(i).getchunk(200)) Then    'here is correct,it have a value<br>.          Label1(i).Caption=""<br>.      Else<br>.          Label1(i).Caption=quesrec.fields(i).getChunk(200)    'here prompt the value is NULL<br>.      Endif<br>.    Next i<br>.End Sub
<br>
<br><hr size=7 width=75%><p>
<a name="followups">Follow Ups:</a><br>
<ul><!--insert: 12226-->
</ul><!--end: 12226-->
<br><hr size=7 width=75%><p>

</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?