DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Vb6 sybntax counterpart of VB.Net.

  1. #1
    Join Date
    Mar 2009
    Posts
    67

    Question Vb6 sybntax counterpart of VB.Net.

    What's the VB6 counterpart of the following codes?

    To insert a record in database with command object parameters:

    Code:
    strSql = "Insert Into tblEmployees (EmpName,DeptartmentID,JoinDate) Values ('" & _
    txtName.Text & "'," & Val(cboDepartment.Value) & ",@JoinDate)"
    com = CreateCommand(strSql)
    
    com.Parameters.Add(New SqlParameter("@JoinDate", SqlDbType.DateTime))
    If (dtpJoinDate.Checked) Then
    	com.Parameters("@JoinDate").Value = Convert.ToDateTime(dtpJoinDate.Value)
    Else
    	com.Parameters("@JoinDate").Value = DBNull.Value
    End If
    
    If com.ExecuteNonQuery = 1 Then
    	MsgBox("Record saved.")
    End If
    To obtain a record from database:

    Code:
    Dim drd As SqlDataReader
    strSql = "Select EmpName,DeptID,JoinDate From tblEmployees Where EmpID=1001"
    drd = CreateReader(strSql)
    If drd.Read Then
    	txtName.Text = drd("EmpName")
    	cboDepartment.Value = drd("DepartmentID")
    
    	If IsDBNull(drd("JoinDate")) Then
    		dtpJoinDate.ResetText()
    		dtpJoinDate.Checked = False
    	Else
    		dtpJoinDate.Value = drd("JoinDate")
    	End If
    End If
    drd.Close()

  2. #2
    Join Date
    Feb 2006
    Posts
    133
    You have to use ADO method. Do some researching, below is an example.

    http://www.timesheetsmts.com/adotutorial.htm

    If you use sql server, here's a small example:

    Code:
        Dim cnn         As ADODB.Connection
        Dim rstSQL      As ADODB.Recordset
        
        Set cnn = New ADODB.Connection
        Set rstSQL = New ADODB.Recordset
        
        cnn.Provider = "sqloledb"
        cnn.ConnectionString = "Server=server01\SQLEXPRESS;" & _
                                "Initial Catalog=dbDatabase;" & _
                                "Trusted_connection=yes;"
            cnn.Open
        
        rstSQL.Open "select * from tblTable", cnn, adOpenDynamic,   adLockReadOnly
        MsgBox rstSQL.Fields(0)
        
        rstSQL.Close
        Set rstSQL = Nothing
        cnn.Close
        Set cnn = Nothing
    Hope this helps.
    Benjamin

  3. #3
    Join Date
    Mar 2009
    Posts
    67

    Question

    Sorry for not to be specific. I want to get the vb6 counterpart for passing dbnull value to database and getting the datareader object (recordset object in case of vb6) and check for dbnull value of one or all of its fields. The following blocks to be specific:

    Code:
    com.Parameters.Add(New SqlParameter("@JoinDate", SqlDbType.DateTime))
    If (dtpJoinDate.Checked) Then
    	com.Parameters("@JoinDate").Value = Convert.ToDateTime(dtpJoinDate.Value)
    Else
    	com.Parameters("@JoinDate").Value = DBNull.Value
    End If
    Code:
    If IsDBNull(drd("JoinDate")) Then
    	'statements.......
            '....................
    Else
    	'statements.......
            '....................
    End If
    I want the vb6 counterpart of the upper mentioned blocks in terms of recordset objects. I'm acquainted in handling recordset objects. Hope this time I'm more specific.

  4. #4
    Join Date
    Feb 2006
    Posts
    133
    Hi,

    Try "null" to check or fill.

    Code:
    rst.fields!Name = null
    Code:
    if isnull(rst.fields!Name) = true then ...
    Hope this is what you need.
    Benjamin

  5. #5
    Join Date
    Mar 2009
    Posts
    67

    Smile

    Thanks!

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Is your question resolved now?

Similar Threads

  1. Replies: 4
    Last Post: 10-17-2005, 08:02 AM
  2. VB6 Calling a VB.Net Dll
    By Graham Russell in forum VB Classic
    Replies: 1
    Last Post: 09-25-2002, 08:13 AM
  3. Is VB.Net difficult or not - OR - How difficult?
    By Michael Culley in forum .NET
    Replies: 6
    Last Post: 06-19-2002, 09:11 AM
  4. Replies: 17
    Last Post: 01-17-2002, 04:32 PM
  5. VB.NET: 3 points of view
    By David Kroll in forum .NET
    Replies: 33
    Last Post: 02-13-2001, 11:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center