Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2008, 09:58 AM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Saving textbox data into Access

Hopefully you seasoned programmers can help a noob like me!

I have a random name generator that populates a textbox and then saves to an Access mdb file. For some reason it will not save the generated name to Access! I can type a name in manually in the textbox and it will save just fine. Below are snippets of the random generator and my saving procedure. Thanks in advance!

Code:
Public Function GetRandomName(ByVal str As String)

        ' name sylables are separated with delimiter ; 
        Dim strDelimiter As String = ";"
        'text files with parts a and b of first name and last name sylables
        'this reads these files into a string
        Dim strFirstNameA As String = My.Resources.FNA
        Dim strFirstNameB As String = My.Resources.FNB
        Dim strLastNameA As String = My.Resources.LNA
        Dim strLastNameB As String = My.Resources.LNB
        'this splits the string into a str array
        'the stings are seperated at delimiter
        Dim FNA = Split(strFirstNameA, strDelimiter)
        Dim FNB = Split(strFirstNameB, strDelimiter)
        Dim LNA = Split(strLastNameA, strDelimiter)
        Dim LNB = Split(strLastNameB, strDelimiter)
        'this will hold parts a and b of first name and c and d of last name
        Dim a As String
        Dim b As String
        Dim c As String
        Dim d As String
        'this selects a random number based on array size and gets
        'the name part stored at that number
        a = FNA(Int((UBound(FNA) - 1 + 1) * Rnd()) + 1)
        b = FNB(Int((UBound(FNB) - 1 + 1) * Rnd()) + 1)
        c = LNA(Int((UBound(LNA) - 1 + 1) * Rnd()) + 1)
        d = LNB(Int((UBound(LNB) - 1 + 1) * Rnd()) + 1)
        'puts it all together and displays
        str = a & b & " " & c & d
        Return str
    End Function
This str is set to txtName.Text
And then my saving procedure...

Code:
' (Truncated)
 objCommand.CommandText = "INSERT INTO CharacterName (CharacterName) VALUES (@CharacterName)"
        objCommand.Parameters.AddWithValue("@CharacterName", txtName.Text)
        objConnection.Open()
        objCommand.ExecuteNonQuery()
        objConnection.Close()

Last edited by iostream212; May 18th, 2015 at 01:01 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access to Word not saving BeckyMack Access 0 April 9th, 2008 07:16 AM
Saving data in database from textbox jainin_shah9 C# 2005 1 February 21st, 2008 08:34 AM
Data Cache not saving rturner003 ASP.NET 2.0 Professional 1 August 8th, 2007 07:29 PM
Saving picture in Access Jennyalex Access 5 August 16th, 2006 07:55 AM
Access Bound forms - auto saving data! jscully Access 6 January 17th, 2005 07:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.