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()