Results 1 to 29 of 29

Thread: Extreme New Guy - Not Even Sure I'm in the Right Place

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Extreme New Guy - Not Even Sure I'm in the Right Place

    Hello all. As the title states, I am extremely new to this world of coding. Once upon a time, many moons ago, I would create applications with Visual Basic 6 - some fairly detailed programs for a hobbyist I think. Anyway, my new hobby (geology) has me wanting to create a simple (for now) database program. It has been so terribly long since I have done any of this and things seemed to have changed quite a lot since then. Allow me to start with a few details:

    - I'm using Visual Studio 2019
    - I'm attempting to create a Windows Form Application (.NET Framework)
    - My database is an older Access database file (.mdb)
    - At this point, I'm simply trying to populate a single (soon to be more I hope) combo box drop down list with the field located in a single column from that .mdb file.
    - To make things as simple as possible, I have a form (frmMain), a combo box (comboNames), a button (cmdPopulate), a second button (cmdExit) and a simple lable.

    My goal here is to load the form and connect to the database (database.mdb) but to only populate the combo box drop down list (comboNames) once the Populate button (cmdPopulate) has been activated. The Exit button (cmdExit) works as it should - it ends the program. I'll share what I have thus far but I keep getting hung up on the connection. I don't seem how to define this line properly:

    Code:
    Dim CNN As New OleBdConnection(Provider = Microsoft.Jet.OLEDB.4.0;Data Source=AppDomain.CurrentDomain.BaseDirectory And "\Database.mdb";Persist Security Info=True)
    It should be understood that I have compiled this code by looking at examples from others that I have found online, without and real understanding of what I'm doing. If there is a simple, database tutorial that I could be directed to which perhaps walks a new guy step by step through the process, that would be wonderful. Otherwise, I am happy to accept some sample code from the gurus and spend the time to understand on my own. In any event, this is my entire code thus far:

    Code:
    Imports System.Data.OleDb
    
    Public Class frmMain
        'Dim CNN As New OleDbConnection(AppDomain.CurrentDomain.BaseDirectory And "\Database\Database.mdb")
        Dim CNN As New OleBdConnection(Provider = Microsoft.Jet.OLEDB.4.0;Data Source=AppDomain.CurrentDomain.BaseDirectory And "\Database.mdb";Persist Security Info=True)
        Dim CMD As New OleDbCommand
    
        Private Sub cmdPopulate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPopulate.Click
            CNN.Open()
            CMD.Connection = CNN
            CMD.CommandText = "select empname from employee"
    
            Dim DR As OleDbDataReader = CMD.ExecuteReader
    
            While DR.Read
                comboNames.Items.Add(DR.Item(0))
            End While
            DR.Close()
        End Sub
    End Class
    Thank you for any and all guidance. It will surely be appreciated! Furthermore, thank you for taking me onboard.

    Cheers!

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    First... welcome!
    Secondly - when you create a connection object, it is expecting a STRING for it's parameter... so this:
    Code:
    Dim CNN As New OleBdConnection(Provider = Microsoft.Jet.OLEDB.4.0;Data Source=AppDomain.CurrentDomain.BaseDirectory And "\Database.mdb";Persist Security Info=True)
    should really be:
    Code:
    Dim CNN As New OleBdConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & AppDomain.CurrentDomain.BaseDirectory" & "\Database.mdb;Persist Security Info=True")
    That'll make it a string. Also, "And" is a logic key word ... it's not the same as "&" which is the string concatenator.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Geology is a rocky subject, but we're all pretty gneiss here.
    My usual boring signature: Nothing

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Aside from TG's comment regarding the connection string and Shaggy's amazing pun...

    While what you are doing is not wrong, I would approach it a bit differently. I would declare a data table at the form level, fill the data table with the result of your query, then bind the control to the data table. Something along these lines:
    Code:
    ' declare an instance of the data table
    Private _employees As DataTable
    Private Sub MyForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' create a new instance of the data table
        _employees = New DataTable()
    
        Try
            ' fetch the data and fill the data table
            Dim commandText = "SELECT * FROM employee"
            Using sqlConnection = New OleDbConnection("my connection string here") ' change this
                Using sqlCommand = New OleDbCommand(commandText, sqlConnection)
                    Using adapter = New SqlDataAdapter(sqlCommand)
                        adapter.Fill(_employees)
                    End Using
                End Using
            End Using
    
            ' bind the control to the data table
            With comboNames
                .DisplayMember = "empname"
                .ValueMember = "MyIdFieldName" ' change this
                .DataSource = _employees
            End With
        Catch ex As Exception
            ' do something with the exception, MessageBox.Show maybe?
        End Try
    End Sub
    Now when you want to reference the primary key or text of the selected record, you would use:
    Code:
    comboNames.SelectedValue ' pk value
    comboNames.SelectedText ' user-friendly text
    And if you need to reference the collection of records again, it is declared at the form level.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    That's a good point, but they were asking about not populating the list until the button was pressed. Normally, binding the control to the list would be the best way to go, but if they have some reason for not wanting the list to be populated until late on...well, what's the reason? One could always create the datatable then not bind it until the button is pressed, but whether or not that is what they'd want to do depends on why they want the populating of the control to be delayed.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by techgnome View Post
    First... welcome!
    Secondly - when you create a connection object, it is expecting a STRING for it's parameter... so this:
    Code:
    Dim CNN As New OleBdConnection(Provider = Microsoft.Jet.OLEDB.4.0;Data Source=AppDomain.CurrentDomain.BaseDirectory And "\Database.mdb";Persist Security Info=True)
    should really be:
    Code:
    Dim CNN As New OleBdConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & AppDomain.CurrentDomain.BaseDirectory" & "\Database.mdb;Persist Security Info=True")
    That'll make it a string. Also, "And" is a logic key word ... it's not the same as "&" which is the string concatenator.

    -tg


    Excellent! Once I'm home from work tonight, I'll go over this and post my results. I very much appreciate your guidance and thank you for the warm welcome. Cheers!
    Last edited by The_Hobbyist; Nov 29th, 2022 at 06:25 PM.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by dday9 View Post
    Aside from TG's comment regarding the connection string and Shaggy's amazing pun...

    While what you are doing is not wrong, I would approach it a bit differently. I would declare a data table at the form level, fill the data table with the result of your query, then bind the control to the data table. Something along these lines:
    Code:
    ' declare an instance of the data table
    Private _employees As DataTable
    Private Sub MyForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' create a new instance of the data table
        _employees = New DataTable()
    
        Try
            ' fetch the data and fill the data table
            Dim commandText = "SELECT * FROM employee"
            Using sqlConnection = New OleDbConnection("my connection string here") ' change this
                Using sqlCommand = New OleDbCommand(commandText, sqlConnection)
                    Using adapter = New SqlDataAdapter(sqlCommand)
                        adapter.Fill(_employees)
                    End Using
                End Using
            End Using
    
            ' bind the control to the data table
            With comboNames
                .DisplayMember = "empname"
                .ValueMember = "MyIdFieldName" ' change this
                .DataSource = _employees
            End With
        Catch ex As Exception
            ' do something with the exception, MessageBox.Show maybe?
        End Try
    End Sub
    Now when you want to reference the primary key or text of the selected record, you would use:
    Code:
    comboNames.SelectedValue ' pk value
    comboNames.SelectedText ' user-friendly text
    And if you need to reference the collection of records again, it is declared at the form level.


    Super awesome! As soon as I get a chance, I'll go over this and do my best to comprehend what is put in front of me. I thank you for your help! It is greatly appreciated... Cheers!
    Last edited by The_Hobbyist; Nov 29th, 2022 at 06:26 PM.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by Shaggy Hiker View Post
    That's a good point, but they were asking about not populating the list until the button was pressed. Normally, binding the control to the list would be the best way to go, but if they have some reason for not wanting the list to be populated until late on...well, what's the reason? One could always create the datatable then not bind it until the button is pressed, but whether or not that is what they'd want to do depends on why they want the populating of the control to be delayed.

    To be fair here, I probably don't know enough yet to know what I'm doing is backwards. . Either way, I'm just very appreciative for the guidance. I'm going to work with both examples and see where this takes me.

    Thank you again!
    Last edited by The_Hobbyist; Nov 29th, 2022 at 06:26 PM.

  9. #9
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    It's not backwards ... It's different and not the way most of use would fill a combobox based on database information. Sometimes though, that's all you need ... just straight up text in a drop down. But... more often than not, you need more -IDs. additional info... and that's where binding comes in handy. When you bind to a datatable, you can the set the .DisplayMember which will then determine which field is shown to the user and you can set the .ValueMember, which will determine what column value is returned when you use the .Value property. It adds a layer of flexibility and power that you may or mat not need now, but at some point you will.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by Shaggy Hiker View Post
    Geology is a rocky subject, but we're all pretty gneiss here.
    It is pretty cool when you are stoned though...granite I don't smoke the stuff though.
    Please remember next time...elections matter!

  11. #11
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    These are so bad ... I need to get the schist outta here.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    It appears to take a boulder person than I to comprehend the language. While I am very appreciative of all your assistance and while I'm sure that it is intended for the crater good, I do find myself struggling immensely. It is true that I have a great apatite to succeed but I'm afraid I must report that I am off to a very rocky start. Of quartz, this doesn't mean that I have given up!! I have an all ore nothing attitude when I put my mind to it - and I'm going to put my mind to it! With that said, I'm afraid that I took for granite my previous experience with VB6 coding from several years ago. It appears crystal clear to me now that I am going to have to start from the very beginning. One of my biggest faults is a fading memory and it pains me to admit that most of what I once knew about VB6 coding has now since escaped me.


    All puns aside:

    Moving away from my initial request of trying to populate a combo box drop down list with data from a database, I am simply going to attempt to understand how a database is created and connected to the project. I see now that I need to start from lesson #1. Furthermore, I will also attempt to understand how to manipulate the database from a form and likewise how to search the database and return the desired results.

    I have found a YouTube tutorial which walks me through, step-by-step, how to connect an .mdf database. I have followed it all the way through and have managed to succeed in creating the same end result as the YouTuber. There is no surprise here - I was merely following along step-by-step. My task and goal now are to go back and understand what I did and why it works. I'll share the you-tube link at the end of this post.

    I'll consider my initial intention of this thread satisfied - not because I succeeded but because it is simply beyond the scope of my comprehension (for now). I do very much appreciate all of the help and direction offered to me. Stay tuned, I'm not going anywhere. For now, I have some reading to do though... Cheers!

    https://www.youtube.com/watch?v=z6W8-g6i-ZE

  13. #13
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    This site has a lot of info for beginners. https://www.homeandlearn.co.uk/NET/vbNet.html

    It's old but still valid. I don't know what your ultimate goal is, this will give you a base to start from.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by wes4dbt View Post
    This site has a lot of info for beginners. https://www.homeandlearn.co.uk/NET/vbNet.html

    It's old but still valid. I don't know what your ultimate goal is, this will give you a base to start from.
    Thank you! It is appreciated.

    Essentially, my end goal is I to create a little program that allows me to create and edit a catalogue of my geology specimens by several criteria (name, classification, hardness, chemical formula, ect...). Likewise, I would like to have photos of the specimen attached and displayed in a picture box when the corresponding database item is viewed. Being able to search by any number of criteria later is the end game.

    I'll get there... I thought I had a better understanding of the language and how to define/sequence things than I do. Sometimes we have to admit that we aren't nearly as far along as we initially thought. As it turns out, I'm a blank slate... Anyway, thank you for the link - I'll put it to good use!

  15. #15
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by The_Hobbyist View Post
    It appears to take a boulder person than I to comprehend the language. While I am very appreciative of all your assistance and while I'm sure that it is intended for the crater good, I do find myself struggling immensely. It is true that I have a great apatite to succeed but I'm afraid I must report that I am off to a very rocky start. Of quartz, this doesn't mean that I have given up!! I have an all ore nothing attitude when I put my mind to it - and I'm going to put my mind to it! With that said, I'm afraid that I took for granite my previous experience with VB6 coding from several years ago. It appears crystal clear to me now that I am going to have to start from the very beginning. One of my biggest faults is a fading memory and it pains me to admit that most of what I once knew about VB6 coding has now since escaped me.


    All puns aside:

    Moving away from my initial request of trying to populate a combo box drop down list with data from a database, I am simply going to attempt to understand how a database is created and connected to the project. I see now that I need to start from lesson #1. Furthermore, I will also attempt to understand how to manipulate the database from a form and likewise how to search the database and return the desired results.

    I have found a YouTube tutorial which walks me through, step-by-step, how to connect an .mdf database. I have followed it all the way through and have managed to succeed in creating the same end result as the YouTuber. There is no surprise here - I was merely following along step-by-step. My task and goal now are to go back and understand what I did and why it works. I'll share the you-tube link at the end of this post.

    I'll consider my initial intention of this thread satisfied - not because I succeeded but because it is simply beyond the scope of my comprehension (for now). I do very much appreciate all of the help and direction offered to me. Stay tuned, I'm not going anywhere. For now, I have some reading to do though... Cheers!

    https://www.youtube.com/watch?v=z6W8-g6i-ZE
    Those were pretty coal puns...
    Please remember next time...elections matter!

  16. #16
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by The_Hobbyist View Post
    ...Essentially, my end goal is I to create a little program that allows me to create and edit a catalogue of my geology specimens by several criteria (name, classification, hardness, chemical formula, ect...). Likewise, I would like to have photos of the specimen attached and displayed in a picture box when the corresponding database item is viewed. Being able to search by any number of criteria later is the end game....
    If I were in your position, this is what I would do:
    1. Create your database schema first
    2. Decide how you plan on storing the image
      1. If you plan on using the windows file system, then your data table would simply need to store the path of the image
      2. If you plan on using the database, then your data table would need to store the bytes and your application would need to convert the image to a byte array and then store the results
      3. Each have their own pros/cons, be sure to search "pros and cons of storing files in database" in your search engine of choice
    3. Use an Object Relationship Manager (aka ORM) to manage the connecting of and representation of your database
      1. I would suggest Dapper
      2. PetaPoco is a good alternative, but they've moved away from being purely open source
      3. Entity Framework is Microsoft's implementation. I hate it with a passion, but it is still an option
    4. Create your UI to manage the various data objects
    5. Use data bindings like I showed in post #4 (the DataSource, DisplayMember, etc.)


    This is not as simple as banging out a RAD application, but it will provide you with more flexibility and will be rock solid (no pun intended).
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    You people are the best! So helpful and supportive. Thank you peeps, I have plenty of things to consider and focus on.

    Cheers!

  18. #18
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    create a simple (for now) database program
    My database is an older Access database file (.mdb)
    Left field thinking - but why not do the whole thing in Access if you have that?
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  19. #19
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    I'd also suggest that you consider SQL Server Express. Access is the database that most people probably start out with, and it's not too bad, but it does have some drawbacks. You probably don't care too much that it doesn't work very well in a multi-user environment, but Access also has a disturbing tendency to become corrupt. Usually, this happens when the database is used across a network, but I've also seen it happen in single user/single computer scenarios. For that reason, I've come to not trust Access all that well.

    However, the program Access is just a front end for a database, which used to be (and can still be) .mdb databases, and are now accdb databases. Frankly, of the two, I prefer the .mdb, since the Jet DB engine is built into Windows. Still, Access is just a front end for the database, and at that it's quite nice. SQL Server Express is a lighter (and free) version of SQL Server, which is Microsoft's enterprise database. The Express version isn't very stripped down, so it's a robust database. It also has it's own front end program, which is SQL Server Management Studio (SSMS). It used to be not just possible, but easy, to get SQL Server without getting (SSMS), and it could be painful to then add SSMS at a later point. These days, it's much easier. For a few years now, SSMS has been much more installer friendly than it used to be. However, Access is still easier to use and more familiar to most people. I know lots of people who use Access to link to SQL Server databases rather than use SSMS, as they find it more user friendly.

    So, Access = easier to use and more familiar, but potentially unreliable. SQL Server Express = more powerful and more reliable, but not quite as easy to use.
    My usual boring signature: Nothing

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by 2kaud View Post
    Left field thinking - but why not do the whole thing in Access if you have that?
    I'm on a mission to get back into some simple VB work. It essentially boils down to wanting to design and build a stand alone program for myself. To Taylor make something to my own needs really and then to have the satisfaction of saying "I did that". I enjoying learning, albeit rather slow at it sometimes.

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by Shaggy Hiker View Post
    I'd also suggest that you consider SQL Server Express. Access is the database that most people probably start out with, and it's not too bad, but it does have some drawbacks. You probably don't care too much that it doesn't work very well in a multi-user environment, but Access also has a disturbing tendency to become corrupt. Usually, this happens when the database is used across a network, but I've also seen it happen in single user/single computer scenarios. For that reason, I've come to not trust Access all that well.

    However, the program Access is just a front end for a database, which used to be (and can still be) .mdb databases, and are now accdb databases. Frankly, of the two, I prefer the .mdb, since the Jet DB engine is built into Windows. Still, Access is just a front end for the database, and at that it's quite nice. SQL Server Express is a lighter (and free) version of SQL Server, which is Microsoft's enterprise database. The Express version isn't very stripped down, so it's a robust database. It also has it's own front end program, which is SQL Server Management Studio (SSMS). It used to be not just possible, but easy, to get SQL Server without getting (SSMS), and it could be painful to then add SSMS at a later point. These days, it's much easier. For a few years now, SSMS has been much more installer friendly than it used to be. However, Access is still easier to use and more familiar to most people. I know lots of people who use Access to link to SQL Server databases rather than use SSMS, as they find it more user friendly.

    So, Access = easier to use and more familiar, but potentially unreliable. SQL Server Express = more powerful and more reliable, but not quite as easy to use.
    Excellent feedback! Thank you for that Shaggy!

  22. #22
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    @wes4dbt: That tutorial looks mostly fine. However to anyone using it I say:

    1. Avoid using the concatenation operator to combine strings.
    2. Look up what string interpolation is.
    3. Also check out the String.Text.StringBuilder object.
    4. Also, you can initialize variables in the same statement as the declaration, something the tutorial neglects to mention.
    Last edited by Peter Swinkels; Dec 3rd, 2022 at 01:53 PM.

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Nov 2022
    Location
    Manitoba, Canada
    Posts
    142

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by Peter Swinkels View Post
    @wes4dbt: That tutorial looks mostly fine. However to anyone who using it I say:

    1. Avoid using the concatenation operator to combine strings.
    2. Look up what string interpolation is.
    3. Also check out the String.Text.StringBuilder object.
    4. Also, you can initialize variables in the same statement as the declaration, something the tutorial neglects to mention.
    Thank you for that Peter! I was hesitant to share the link because I don't know enough to know whether or not it was sound advice. It felt as though it were however, to the untrained such as myself, anything might! I appreciate your comment. Thank you again.

  24. #24
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    @The_Hobbyist:
    You're welcome.

  25. #25
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by Peter Swinkels View Post
    @wes4dbt: That tutorial looks mostly fine. However to anyone using it I say:

    1. Avoid using the concatenation operator to combine strings.
    2. Look up what string interpolation is.
    3. Also check out the String.Text.StringBuilder object.
    4. Also, you can initialize variables in the same statement as the declaration, something the tutorial neglects to mention.
    Yeah, I know it's old. But for a beginner who is only looking at .Net as a hobby, it will do the job.

    I'd like to refer to a more up to date tutorial site but I don't know of any. Maybe someone else could chime in with a more up to date tutorial site.

  26. #26
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Mais I’ve got one me in my signature, but I’m no writer so I feel like it ain’t the best.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  27. #27
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    @wes4dbt:
    As I said, that tutorial is mostly fine. I thought I would just give a few tips.

  28. #28
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    If you are doing only a few concatenations, then don't worry about it. It's a little slow, but computers are fast. A few of them, even if a bit slow, will still happen in no perceptible time. If you are using LOTS of strings and LOTS of concatenations, then there will be better ways.
    My usual boring signature: Nothing

  29. #29
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: Extreme New Guy - Not Even Sure I'm in the Right Place

    Quote Originally Posted by The_Hobbyist View Post
    I'm on a mission to get back into some simple VB work. It essentially boils down to wanting to design and build a stand alone program for myself. To Taylor make something to my own needs really and then to have the satisfaction of saying "I did that". I enjoying learning, albeit rather slow at it sometimes.
    for a standalone Database I think that Access is more than enough.
    Here is a sample I did a while back for sombody, it creates a Access Database an adds a Table to that Database

    Code:
    Option Strict On
    Imports System.Data.OleDb
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            'Add the COM Reference, "Microsoft ADO Ext. 6.0 for DLL and Security"
            ' create the empty DB file
            Dim cat As New ADOX.Catalog()
            cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Train\TrainData.mdb")
            cat = Nothing
    
            'here you create your Table in the Database
            Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Train\TrainData.mdb")
            con.Open()
            'create your Table tbl_Train
            Dim sSQL As String = <sql> 
            Create Table tbl_Train
            ([TR_ID] AutoIncrement CONSTRAINT PRIMARYKEY PRIMARY KEY
            , [TR_arrivalLocationName] varChar(50)
            , [TR_pnrCode] varChar(50)
            , [TR_serviceLevel] varChar(50)
            , [TR_lastName] varChar(50)
            , [TR_firstName] varChar(50)
            , [TR_wagon] INT
            , [TR_seat] INT
            , [TR_transportMeanName] varChar(50)
            , [TR_couponId] varChar(50))
            </sql>.Value
            ExecuteSQL(con, sSQL)
    
        End Sub
    
        Public Function ExecuteSQL(ByVal Con As OleDb.OleDbConnection, _
                                      ByVal sSQL As String, _
                                      Optional ByRef ErrMessage As String = Nothing, _
                                      Optional ByVal TransAction As  _
                                      OleDb.OleDbTransaction = Nothing) As Integer
            ErrMessage = Nothing
            Try
                Dim Result As Integer = 0
                Using Cmd As New OleDb.OleDbCommand(sSQL, Con, TransAction)
                    Result = Cmd.ExecuteNonQuery
                End Using
                Return Result
            Catch ex As Exception
                ErrMessage = ex.Message
                Return 0
            End Try
        End Function
    good luck
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

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