Results 1 to 6 of 6

Thread: [RESOLVED] Grab data from MS Access and use it again in SQL!

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    3

    Question [RESOLVED] Grab data from MS Access and use it again in SQL!

    Hi folks,


    I need help using the data I retrieve from Access in SQL syntax. This is my code btw:


    f Code:
    1. Imports System.Data.OleDb
    2. Public Class Form1
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.  
    6.         Dim con As New OleDb.OleDbConnection
    7.         Dim ds As New DataSet
    8.         Dim da As OleDb.OleDbDataAdapter
    9.         Dim sql As String
    10.         Dim nilai As String
    11.  
    12.         con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Users\hadi\Desktop\SISTEM PENGUNDIAN ELEKTRONIK\SISTEM PENGUNDIAN ELEKTRONIK\Mini Projek_database.mdb"
    13.         con.Open()
    14.  
    15.         sql = "SELECT StudentID FROM Calon"
    16.  
    17.  
    18.         da = New OleDb.OleDbDataAdapter(sql, con)
    19.         da.Fill(ds, "Calon")
    20.  
    21.         nilai = ds.Tables("Calon").Rows(0).Item("StudentID")
    22.         RadioButton1.Text = nilai
    23.  
    24.         '   Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\hadi\Desktop\SISTEM PENGUNDIAN ELEKTRONIK\SISTEM PENGUNDIAN ELEKTRONIK\Mini Projek_database.mdb")
    25.         Dim cmd As OleDbCommand
    26.  
    27.  
    28.  
    29.  
    30.  
    31.         If RadioButton1.Checked = True Then
    32.  
    33.             cmd = New OleDbCommand("UPDATE Calon SET Jumlah_Undi=Jumlah_Undi+1 WHERE StudentID = 'RadioButton1.text'", con)
    34.  
    35.  
    36.  
    37.  
    38.             Dim sdr As OleDbDataReader = cmd.ExecuteReader()
    39.  
    40.  
    41.         ElseIf RadioButton2.Checked = True Then
    42.  
    43.             cmd = New OleDbCommand("UPDATE Calon SET Jumlah_Undi=Jumlah_Undi+1 WHERE StudentID = '01DIP09F107'", con)
    44.  
    45.  
    46.             Dim sdr As OleDbDataReader = cmd.ExecuteReader()
    47.  
    48.         End If



    Using RadioButton1.text in the SQL syntax don't work even the RadioButton1.text hold the value of StudentID. but using StudentID value like eg: 01DIP09F107 is working good! Note that 01DIP09F107 is in my StudentID column.

    Now where did I do wrong? Thanks for any help. I'm looking at this thread http://www.vbforums.com/showthread.php?t=356711 right bow and comparing my code...
    Last edited by sg552; Nov 21st, 2009 at 02:50 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
  •  



Click Here to Expand Forum to Full Width