SQL Server > SQL Server Forums > SQL Server Data Access > Overwhelmed, New to VB

Unanswered Overwhelmed, New to VB

  • Monday, April 30, 2012 5:29 AM
     
     

    So I've been fidgeting around with VB, and I made this small "easy" program I got most of the major problems out of the way,but now I'm stuck. The program is suppose to make an SQL message to a specific folder in "C:\temp\",but theirs one problem I don't know what value to put on "Archive_to_read" and its really starting to bug me....any help is appreciate.

    This is the Code:

    Imports System.Data.OleDb



    Public Class Form1
        Dim Conection_to_Access As OleDbConnection
        Dim comandodeSQL As OleDbCommand
        Dim lineadeSQL As String
        Dim ds, dsdoctor As New DataSet
        Dim eladapter As OleDb.OleDbDataAdapter


        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button1.Click
            Dim i As Integer
            Dim campo0, campo2, campo1, linea As String
            Dim archive_to_read As String
            Dim limite As Integer

            REM Creando la conexión al Banco de Datos  

            Conection_to_Access = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\Bancodedatospractica.mdb;")

            Conection_to_Access.Open()
            lineadeSQL = "select * from  customers;"
            eladapter = New OleDb.OleDbDataAdapter(lineadeSQL, Conection_to_Access)
            eladapter.Fill(ds, "tablavirtual")


            Select Case archive_to_read
                Case "nono"
                    limite = 500
                Case Else
                    limite = 3
            End Select
            MsgBox(limite)
            For i = 0 To limite

                campo0 = Val(ds.Tables("tablavirtual").Rows(i).Item(0))
                campo1 = (ds.Tables("tablavirtual").Rows(i).Item(1))
                campo2 = Val(ds.Tables("tablavirtual").Rows(i).Item(2))
                linea = campo0 + "  " + campo1 + "    " + campo2

                ListBox1.Items.Add(linea)
            Next
            Conection_to_Access.Close()

        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim i As Integer
            Dim campo0, campo1, campo2, linea As String


            REM Creando la conexión al Banco de Datos  
            Conection_to_Access = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\Bancodedatospractica.mdb;")
            Conection_to_Access.Open()
            lineadeSQL = "tablavirtual (campo1 varchar(10), campo2 int);"
            On Error GoTo final
            eladapter = New OleDb.OleDbDataAdapter(lineadeSQL, Conection_to_Access)
            eladapter.Fill(ds, "tablavirtual")
            Conection_to_Access.Close()
            GoTo pepe

    final:
            MsgBox("ERROR")
    pepe:

        End Sub




        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            WindowState = 2

        End Sub
    End Class

    • Changed Type FJS7 Monday, April 30, 2012 6:50 AM lack of replies
    •  

All Replies

  • Monday, April 30, 2012 10:01 AM
    Moderator
     
     

    Hello,

    file .mdb = Access database ? I suppose that is why you define the connection as Conection_to_Access. But i have 2 questions :

    - the version of the Access ( the year of release )

    - why to put this Access database in the C:\Temp folder ?

    For Archive_to_read , it seems that your application is really using only value "nono".If Archive_To_read = "nono", the application is loading in the ListBox1 a maximum of 500 items , if Archive-to-read not equals to "nono", you limit the maximum items in ListBox1 to 3.

    I am not a fan of VB but to write in VB , i can do it.Please, could you tell us which is the version of your VB ( 6,2003,2005,2008,2010 ) ? I am surprised by REM , i thought it has been replaced by '

    Have you thought to foresee the treatement of exception ? MsgBox("Error") does not bring anything in case of exception.

    I would suggest to read http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbexception.aspx and especially the code samples ( in case of error, the ErrorCode,Message,Source,StackTrace,TargetSite properties could be useful to find the origin if the exception ).

    We are waiting for your feedback to try to help you more efficiently.

    Have a nice day

    PS : i have not understood your explanation about the change of type "lack of replies".When you posted the 1st, it was around 8 AM in France and midnight in Seattle.It would be difficult to find someone to help you as most of the people are sleeping  except from China or India.

    But if you changed the type because you thought that a question is always more attractive than a general discussion, you are right for most of the visitors of forums as they are thinking : too much work for nothing to earn and i am sad versus this behaviour.


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.


  • Sunday, May 06, 2012 4:55 AM
    Moderator
     
     

    Hello,

    No news from you since more a week.

    Have you found a solution to your problem ? If yes, please, could you share it ? ( it could be useful for other people facing the same problem )

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.