Results 1 to 6 of 6

Thread: VB2005 Make connection in code and use wizzards????

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    VB2005 Make connection in code and use wizzards????

    Hello my friends,

    Is it possible to build my connectionstring in code like this:

    VB Code:
    1. Imports System.Data.OleDb
    2. Dim oOleDbConnection As OleDbConnection
    3. Dim sConnString As String = _
    4.     "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    5.     "Data Source=C:\myPath\myJet.mdb;" & _
    6.     "User ID=Admin;" & _
    7.     "Password="
    8. oOleDbConnection = New OleDb.OleDbConnection(sConnString)
    9. oOleDbConnection.Open()

    And then use the wizards to make a detailform and use the binding navigator, etc...???

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: VB2005 Make connection in code and use wizzards????

    I don't hink you can do that... Using either wizards or code entirely, but not mixing the 2... Maybe I'm wrong though

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: VB2005 Make connection in code and use wizzards????

    Thank you stanav..

    You know what the problem is....

    I would love to do everything in code...but I am afraid that I will run into problems.

    Things like:
    -navigating through the records
    -Detail forms etc...

    And those are things wich you can do very nice with the wizzards...

  4. #4
    Fanatic Member
    Join Date
    Aug 2006
    Location
    Chicago, IL
    Posts
    514

    Re: VB2005 Make connection in code and use wizzards????

    I do all of my programming for databases in code. I've never used a wizard. I have no problem with updating, inserting, deleting, and navigating. I can show you...?
    Warren Ayen
    Senior C# Developer
    DLS Software Studios (http://www.dlssoftwarestudios.com/)

    I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
    Hey! If you like my post, or I solve your issue, please Rate Me!

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: VB2005 Make connection in code and use wizzards????

    Quote Originally Posted by warrenayen
    I do all of my programming for databases in code. I've never used a wizard. I have no problem with updating, inserting, deleting, and navigating. I can show you...?
    I would appreceate that very very much....

    I hope to hear from you..

    Thanks in advance

  6. #6
    Fanatic Member
    Join Date
    Aug 2006
    Location
    Chicago, IL
    Posts
    514

    Re: VB2005 Make connection in code and use wizzards????

    Well I e-mailed you the functions that I created, but it's really this simple:

    VB Code:
    1. Dim sqlConnection As SqlClient.SqlConnection
    2. Dim SqlDataAdapter As SqlClient.DataAdapter
    3. Dim myTable as DataTable
    4. Dim sqlCommand as SqlClient.SqlCommand
    5.  
    6. sqlConnection = New SqlClient.SqlConnection("connection string")
    7. sqlDataAdapter = New SqlClient.SqlDataAdapter("SQL Query", sqlConnection)
    8.  
    9. myTable = New DataTable("table name")
    10.  
    11. sqlDataAdapter.Fill(myTable)
    12.  
    13. 'this will update a record. What you do is make sure you have the current row's ID. All tables should have a Primary Key.
    14. sqlCommand = New SqlClient.SqlCommand("UPDATE tablename SET field = '" & value & "' WHERE IDField = '" & value & "'", sqlConnection) 'change the "value" to the real value, and the tablename, field, and IDField to the fieldnames
    15. sqlConnection.Open
    16. sqlCommand.ExecuteNonQuery
    17. sqlConnection.Close
    18.  
    19. 'this will insert a record. What you do is make sure you have the current row's ID. All tables should have a Primary Key.
    20. sqlCommand = New SqlClient.SqlCommand("INSERT INTO tablename (field = '" & value & "') VALUES (" & value & "," & value & ") WHERE IDField = '" & value & "'", sqlConnection) 'change the "value" to the real value, and the tablename, field, and IDField to the fieldnames
    21. sqlConnection.Open
    22. sqlCommand.ExecuteNonQuery
    23. sqlConnection.Close
    24.  
    25. 'this will update a record. What you do is make sure you have the current row's ID. All tables should have a Primary Key.
    26. sqlCommand = New SqlClient.SqlCommand("DELTE tablename WHERE IDField = '" & value & "'", sqlConnection) 'change the "value" to the real value, and the tablename, field, and IDField to the fieldnames
    27. sqlConnection.Open
    28. sqlCommand.ExecuteNonQuery
    29. sqlConnection.Close
    30.  
    31. 'this will "navigate"
    32. Me.TextBox1.Text = myTable.Rows(index)("Fieldname") 'change index to the selected row, and Fieldname to the name of the column you want to display

    That's the code I use
    Warren Ayen
    Senior C# Developer
    DLS Software Studios (http://www.dlssoftwarestudios.com/)

    I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
    Hey! If you like my post, or I solve your issue, please Rate Me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width