Hosting Gratis

Pages

Monday, December 3, 2012

Update ODBC Records in VB6

  

  • Open a new Standard EXE Visual Basic project. From the menu, select "Project" and then "References." Click the check box next to "Microsoft ActiveX Data Objects 2.x" where "x" is the highest number available on your machine. Click the "OK" button to save and close.

  • Add a new button to the default "Form1" that was created by default. Name the button "cmdUpdate" and set the caption equal to "Update." This button will save any updates directly to the appropriate table(s).
  • Declare variables to store the ADODB objects and a string variable for the SQL statement itself.
    Dim oConn As ADODB.Connection
    Dim strSQL As String
    Dim oCmd as ADODB.Command

  • Connect to the database in the "Form_Load" event of "Form1."
    Set oConn = New ADODB.Connection
    oConn.ConnectionString = "DSN=MyDBName;Uid=admin;Pwd=password;"
    oConn.Open

  • Code the SQL for the "update" statement in the click event of "cmdUpdate."
    strSQL = "UPDATE myTable SET columnName = 'NewName' WHERE ID = 3;"
    oCmd.CommandText = strSQL
    oCmd.Execute

  • 0 komentar:

    Post a Comment