Results 1 to 9 of 9

Thread: Ado.net/sql/odbc

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Chesterfield, UK
    Posts
    162

    Ado.net/sql/odbc

    In the past I've always use ADODB in vb.net for accessing data. I use PervasiveSQL which supports adCmdTableDirect so it allows me to move up and down tables, edit, delete create new records etc.

    I thought it was about time I looked at taking the SQL approach. What I can't get my head around is which method to use, you've go system.data.oledb, system.data.odbc and system.data.sqlclient. On top of that there's seems to be no recordset to retrieve a SQL query into, so is it possible to have a local recordset to work on and make changes or do you just issue SQL UPDATE commands?

    If somebody could shed some light on the best method I would appreciate it and any decent links to exampes.

    Thanks

  2. #2
    Lively Member
    Join Date
    Apr 2005
    Posts
    91

    Re: Ado.net/sql/odbc

    Hi,
    Are you still thinking of connecting to your Pervasive DB? If so does it have
    an ODBC driver for .NET.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Chesterfield, UK
    Posts
    162

    Re: Ado.net/sql/odbc

    It does have its own .Net adaptor but I would prefer not to use so in theory I could have any database at the back end.

  4. #4
    Lively Member
    Join Date
    Apr 2005
    Posts
    91

    Re: Ado.net/sql/odbc

    Hi,
    This is an INSERT in Oledb Using Parameters
    VB Code:
    1. Dim sqlSaveCust As String = ("INSERT INTO [Customer] (CustCode, SuppCode, CustName, CustAddr1, CustAddr2, CustAddr3, CustAddr4, CustContact, CustPhone, CustFax, CustMobile, CustSupp) " _
    2.                                               & "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
    3.         Dim CMDSaveCust As New OleDb.OleDbCommand(sqlSaveCust, TrenConn)
    4.         CMDSaveCust.CommandType = CommandType.Text
    5.  
    6.         CMDSaveCust.Parameters.Add("@CustCode", OleDb.OleDbType.VarChar, 15).Value = Me.TxtCustCode.Text
    7.         CMDSaveCust.Parameters.Add("@SuppCode", OleDb.OleDbType.VarChar, 15).Value = Me.TxtSuppCode.Text
    8.         CMDSaveCust.Parameters.Add("@CustName", OleDb.OleDbType.VarChar, 50).Value = Me.TxtCustName.Text
    9.         CMDSaveCust.Parameters.Add("@CustAddr1", OleDb.OleDbType.VarChar, 30).Value = Me.TxtCustAdd1.Text
    10.         CMDSaveCust.Parameters.Add("@CustAddr2", OleDb.OleDbType.VarChar, 30).Value = Me.TxtCustAdd2.Text
    11.         CMDSaveCust.Parameters.Add("@CustAddr3", OleDb.OleDbType.VarChar, 30).Value = Me.TxtCustAdd3.Text
    12.         CMDSaveCust.Parameters.Add("@CustAddr4", OleDb.OleDbType.VarChar, 30).Value = Me.TxtCustAdd4.Text
    13.         CMDSaveCust.Parameters.Add("@CustCont", OleDb.OleDbType.VarChar, 30).Value = Me.TxtCustCont.Text
    14.         CMDSaveCust.Parameters.Add("@CustPhone", OleDb.OleDbType.VarChar, 20).Value = Me.TxtCustPhone.Text
    15.         CMDSaveCust.Parameters.Add("@CustFax", OleDb.OleDbType.VarChar, 20).Value = Me.TxtCustFax.Text
    16.         CMDSaveCust.Parameters.Add("@CustMob", OleDb.OleDbType.VarChar, 20).Value = Me.TxtCustMob.Text
    17.         CMDSaveCust.Parameters.Add("@CustSupp", OleDb.OleDbType.Boolean).Value = Me.CB1CustSupp.SelectedIndex
    18.  
    19.         Conn_Open()
    20.         CMDSaveCust.ExecuteNonQuery()
    21.         Conn_Close()
    It all depends on your backend DB and the driver it supplies for .NET also if your DB supports Ansi SQL.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Chesterfield, UK
    Posts
    162

    Re: Ado.net/sql/odbc

    Thanks for that. What about queries, in your example you have the customer table but behind that you could have a table for unpaid invoices. How do you query that into a recordset, work on it and push it back to the database. From what I can see there's no recordsets in ADO.NET.

  6. #6
    Lively Member
    Join Date
    Apr 2005
    Posts
    91

    Re: Ado.net/sql/odbc

    Hi,
    No you don't have recordsets but you do have Datasets and DataRows these are what you work with.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Chesterfield, UK
    Posts
    162

    Re: Ado.net/sql/odbc

    Ok I'll look into them. Do they write back the the DB or is it a case of running a SQL command.

    Thanks for the advice.

  8. #8
    Lively Member
    Join Date
    Apr 2005
    Posts
    91

    Re: Ado.net/sql/odbc

    Hi,
    You can do it either way, but in .NET you disconnect, work with Data and then re-connect to save changes.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Location
    Chesterfield, UK
    Posts
    162

    Re: Ado.net/sql/odbc

    Is there not a overhead in reconnecting all the time? or do you keep the connection open just the query you close.

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