Results 1 to 5 of 5

Thread: Rusty SQL Statement

  1. #1

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Rusty SQL Statement

    VB Code:
    1. Private Sub DatabaseM_Click()
    2.     Dim ADOCn       As ADODB.Connection
    3.     Dim rsValues    As ADODB.Recordset
    4.     Dim ConnString  As String
    5.         ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    6.             "Data Source=" & CommonDialog1.FileName & ";" & _
    7.             "Persist Security Info=False"
    8.         Set ADOCn = New ADODB.Connection
    9.    
    10.     ADOCn.ConnectionString = ConnString
    11.     ADOCn.Open
    12.     Set rsValues = New ADODB.Recordset
    13.     rsValues.Open "SELECT * FROM Overview", ADOCn, adOpenKeyset, adLockOptimistic, adCmdText
    14.     With rsValues
    15.         .AddNew
    16.         .Fields("ProjName").Value = ProjNameT.Text
    17.         .Fields("OilComp").Value = OilCoT.Text
    18.         .Fields("GeoCon").Value = GeoT.Text
    19.         .Fields("SurveyCon").Value = SurvT.Text
    20.         .Fields("DrillCon").Value = DrillT.Text
    21.         .Fields("Total").Value = AcresT.Text
    22.         .Fields("TodDate").Value = DateT.Text
    23.         .Fields("StartDate").Value = StartT.Text
    24.         .Update
    25.  
    26. End With
    27. ProjNameT.Text = vbNullString
    28. OilCoT.Text = vbNullString
    29. GeoT.Text = vbNullString
    30. SurvT.Text = vbNullString
    31. DrillT.Text = vbNullString
    32. AcresT.Text = vbNullString
    33. DateT.Text = vbNullString
    34. StartT.Text = vbNullString
    35. rsValues.MoveFirst
    36. End Sub

    And also, Say that i have 70 textboxes instead of 9, is there anyway that i could use ADO without typing out all 70 textboxes and all 70 fields?

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Rusty SQL Statement

    Quote Originally Posted by cid
    And also, Say that i have 70 textboxes instead of 9, is there anyway that i could use ADO without typing out all 70 textboxes and all 70 fields?
    I dont think so, you'll just have to type away :-/

    as for the code, remmber to set your connection and recordset = nothing when finished

    Pino

  3. #3
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Rusty SQL Statement

    Quote Originally Posted by cid
    And also, Say that i have 70 textboxes instead of 9, is there anyway that i could use ADO without typing out all 70 textboxes and all 70 fields?
    Yes, assuming the fields in your recordset are in the same order of the Textbox Array:


    VB Code:
    1. Set rsValues = New ADODB.Recordset
    2.     rsValues.Open "SELECT * FROM Overview", ADOCn, adOpenKeyset, adLockOptimistic, adCmdText
    3.     With rsValues
    4.         .AddNew
    5.              With .Fields
    6.                   For a = 1 To .Count - 1
    7.                      .Value = Text1.Item(a).Text & ""
    8.                   Next a
    9.               End With        
    10.         .Update
    11.     End With
    Last edited by Mark Gambo; Nov 1st, 2005 at 11:42 AM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Rusty SQL Statement

    you didnt say array :grr:

    Pino

  5. #5
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628

    Re: Rusty SQL Statement

    Sure, loop through a control collection specifying that they be text boxes. Then if you either A) Name the text box as the field name in the Db, or B) set a property each control has in VB which can just store data you can use.. I forget the property name... then you can do...

    VB Code:
    1. Dim CTL as Control
    2. For Each CTL in Controls
    3. 'Some test to make sure it is a textbox
    4. rs.fields(CTL.Name).Value=CTL.Text
    5. Next CTL

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