Password Validation in Visual Studio 2012 - using BindingSource and SQL database - sql-server

I need help. Need to do password validation and have no idea why it doesn't work. Could someone tell me what my code is missing or what is actually wrong with my way of thinking? I am connecting it to dataset2 where is the table called Users2. Table consists of two columns: 'Username' and 'Password'. Users2BiningSource.Find should be returning value of an index where a current query is. The returned value is always -1, what I guess means that is not found (false). I am using Microsoft Visual Studio 2012 along with SQL server 2008 SP3, all on windows 7. Thank you for your time and help!
Imports Hotel_Booking_System.DataSet2TableAdapters
Public Class Logging
Public Sub check_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Check_Details()
End Sub
Private Sub Quit_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
Public Sub Logging_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Users2TableAdapter.Fill(Me.DataSet2.Users2)
'TODO: This line of code loads data into the 'DataSet2.Users2' table. You can move, or remove it, as needed.
End Sub
Public Sub Check_Details()
Me.Users2BindingSource.AddNew()
Dim Usrnm As String = ""
Usrnm = txtUsername.Text
Dim Pswrd As String = ""
Pswrd = txtPassword.Text
Dim Found As Integer
Found = Users2BindingSource.Find("Username", Usrnm)
Dim Found2 As Integer
Found2 = Users2BindingSource.Find("Password", Pswrd)
If Found >= 0 And Found2 >= 0 And Usrnm = "Admin" Then
Me.Hide()
Booking.Show()
ElseIf Found >= 0 And Found2 >= 0 Then
Me.Hide()
Rooms.Show()
Else
MsgBox("Wrong username or password. Please try again", MsgBoxStyle.DefaultButton1, "SOMETHING WENT WRONG")
End If
Label1.Text = Found 'checking the value of found
Label2.Text = Found2 ' checking the value of found2
End Sub
End Class

Related

argument out of range parameter name index

since i have the code of the auto generated text box
Insert data from auto generated textbox to SQL Server database
i am try to write a code for ensuring of the auto generated text box in FlowLayoutPanel1 contain data
the auto generated text box build depends on the number in Val(Label2.Text) of the real part
and if any text box is null or empty then the process will stop until fill all fields
the auto generated text box will be like this if the Val(Label2.Text)
is equal to 3
so i try this in the save button
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
For k As Integer = 1 To Val(Label2.Text)
If String.IsNullOrEmpty(FlowLayoutPanel1.Controls(i).Text) Then
MsgBox("Error , fill all text box")
Return
Else
UpdateUsers()
i += 1
End If
Next
MsgBox("Done , add all data to database ")
Button3.Enabled = False
End Sub
so i getting error after leave some text box and back to fill it again
and the all of form code is
Imports System.Data.SqlClient
'library for create folders
Imports System.IO
Public Class part
Dim cLeft As Integer = 1
Dim top1 As Integer = 5
Dim i As Integer = 0
Dim path1 As String
Dim cmd As SqlCommand
Public Sub AddNewTextBox()
Dim txt As New System.Windows.Forms.TextBox()
txt.Top = cLeft * 30
txt.Left = 100
'txt.Text = "TextBox " & Me.cLeft.ToString
cLeft = cLeft + 1
txt.ForeColor = Color.White
txt.BackColor = Color.Gray
txt.Font = New Font("Arial", 14.0, FontStyle.Regular)
txt.Size = New Size(350, 31)
txt.Location = New Point(156, 130 + top1)
txt.TextAlign = HorizontalAlignment.Center
FlowLayoutPanel1.Controls.Add(txt)
End Sub
Private Sub part_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'college part number
Label2.Visible = False
'college path folder
Label3.Visible = False
For m As Integer = 1 To Val(Label2.Text)
AddNewTextBox()
top1 = top1 + 35
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub UpdateUsers()
Using cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Hazim M\Desktop\stud_project\stud_project\Database1.mdf;Integrated Security=True;User Instance=True")
Using cmd As New SqlCommand("INSERT INTO college_part ([name],[coll_of_part],[part_path]) Values (#name,#coll_of_part,#part_path);", cn)
If i < Val(Label2.Text) Then
path1 = Label3.Text & "\" & FlowLayoutPanel1.Controls(i).Text.Trim & Date.Now.Year
cmd.Parameters.Add("#name", SqlDbType.NVarChar).Value = FlowLayoutPanel1.Controls(i).Text
cmd.Parameters.Add("#coll_of_part", SqlDbType.NVarChar).Value = Label1.Text
cmd.Parameters.Add("#part_path", SqlDbType.NVarChar).Value = path1
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
If Not Directory.Exists(path1) Then
Directory.CreateDirectory(path1)
Else
MsgBox("folder is existing")
End If
End If
End Using
End Using
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
For k As Integer = 1 To Val(Label2.Text)
If String.IsNullOrEmpty(FlowLayoutPanel1.Controls(i).Text) Then
MsgBox("Error , fill all text box")
Return
Else
UpdateUsers()
i += 1
End If
Next
MsgBox("Done , add all data to database ")
Button3.Enabled = False
End Sub
End Class
thank u
I think you need to move dim i Integer=0 to local variable in the Button3_click method. ANd Pass i to the UpdateUser call (add the param to UpdateUser). The current global i keeps adding 1 and eventually out of range.

Login form cant connect to database

I cannot connect to my database, i receive message "invalid user or password " even if the password is correct, what should i do anyone any idea or my code is wrong here are all my code for login form/
here is my code
Imports System.Data.SqlClient
Public Class LoginForm
Private Sub UsersBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles UsersBindingNavigatorSaveItem.Click
Me.Validate()
Me.UsersBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DataSet1)
End Sub
Private Sub LoginForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DataSet1.users' table. You can move, or remove it, as needed.
Me.UsersTableAdapter.Fill(Me.DataSet1.users)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connection As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database_topdent.mdf;Integrated Security=True")
Dim command As New SqlCommand("Select * from users where User = #user and Password = #password ", connection)
command.Parameters.Add("#user", SqlDbType.VarChar).Value = UserTextBox.Text
command.Parameters.Add("#password", SqlDbType.VarChar).Value = PasswordTextBox.Text
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable()
adapter.Fill(table)
If table.Rows.Count() <= 0 Then
MessageBox.Show("username or textbox invalid")
Else
Form1.Show()
Me.Hide()
End If
End If
End Sub
End Class
This is so confusing.
You need to check for the username and password, not just count the rows. And that table.rows.count "<=0" ? makes no sense to me.
I can see where you were going with it, but its wrong. And the question itself is not clarified enough. But assuming this is a login form. Try this>
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1_Click
Dim connection As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database_topdent.mdf;Integrated Security=True")
Dim command As New SqlCommand("Select * from [users] where [User] = #1 and [Password] = #2 ", connection)
connection.Open()
command.Parameters.AddWithValue("#1", UserTextBox.Text)
command.Parameters.AddWithValue("#2", PasswordTextBox.Text)
Using dr As SqlDataReader = command.ExecuteReader
Dim userFound As Boolean = False
Dim Name As String = ""
While dr.Read
userFound = True
Name = dr("User").ToString
End While
If userFound = True Then
MsgBox("Yes!")
ElseIf userFound = False Then
MsgBox("nay")
End If
End Using
connection.close()
End Sub
Just make sure your columns are set to vchar. I'm not able to test it, but it should work.
First you need to open the connection. Then you need to read the data in your database with the reader. then, if username and password is found, present a msg or whatever you want.
I'm sure there are better ways to do this, but here I am playing a quick good samaritan.
UPDATE #With permissions
1. Add another column named "Permissions"
2. Create a Module.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1_Click
Dim connection As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database_topdent.mdf;Integrated Security=True")
Dim command As New SqlCommand("Select * from [users] where [User] = #1 and [Password] = #2 ", connection)
connection.Open()
command.Parameters.AddWithValue("#1", UserTextBox.Text)
command.Parameters.AddWithValue("#2", PasswordTextBox.Text)
Using dr As SqlDataReader = command.ExecuteReader
Dim userFound As Boolean = False
While dr.Read
userFound = True
User1 = dr("User").ToString
Permissions = dr("Permissions").ToString
End While
If userFound = True Then
MsgBox("Yes!")
ElseIf userFound = False Then
MsgBox("nay")
End If
End Using
connection.close()
End Sub
A module
Module Module1
Public User1 As String
Public Permissions As String
End Module
And then call stuff in your forms...
For example in your main form or wherever, if you have 2 buttons on load form you can do
If Permissions = "admin" then
Button1.enabled = true
else if Permissions = "user" then
msgbox(fu)
end if
Hello here are my code for login with admin/user it works, but know i want to make permission example when user is logged in not have full access , but the admin is full access..
Here are all my codes for ' Login_Form '
Imports System.Data.SqlClient
Module Module1
Public User1 As String
Public Permissions As String
End Module
Public Class LoginForm
Private Sub UsersBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles UsersBindingNavigatorSaveItem.Click
Me.Validate()
Me.UsersBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DataSet1)
End Sub
Private Sub LoginForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DataSet1.users' table. You can move, or remove it, as needed.
Me.UsersTableAdapter.Fill(Me.DataSet1.users)
If Permissions = "admin" Then
Button1.Enabled = True
ElseIf Permissions = "user" Then
Form1.RaportetToolStripMenuItem.Visible = False
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connection As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database_topdent.mdf;Integrated Security=True")
Dim command As New SqlCommand("Select * from [Table_login] where [Username] = #1 and [Password] = #2 ", connection)
connection.Open()
command.Parameters.AddWithValue("#1", UserTextBox.Text)
command.Parameters.AddWithValue("#2", PasswordTextBox.Text)
Using dr As SqlDataReader = command.ExecuteReader
Dim userFound As Boolean = False
Dim Name As String = ""
While dr.Read
userFound = True
Name = dr("Username").ToString
End While
If userFound = True Then
Form1.Show()
ElseIf userFound = False Then
MsgBox("Username or password is wrong!!!!!! ")
End If
End Using
connection.Close()
If Permissions = "user1" Then
Form1.RaportetToolStripMenuItem.Visible = False
End If
End Sub
End Class

How to update/modify an existing row in an Access Database using Visual Basic

I am having difficulty updating an existing row in an Access Database using VB. I want to be able to make changes to fields in an already populated existing row in my access table.
The code I have relates to adding a new record at the bottom of the table rather than the above.
Public Class Form1
Dim objConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = StudentDatabase.accdb")
Dim objStudentDA As New OleDb.OleDbDataAdapter("Select * FROM Student", objConnection)
Dim objStudentCB As New OleDb.OleDbCommandBuilder(objStudentDA)
Dim objDs As New DataSet()
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
If txtStudentNum.Text <> "" And txtSurname.Text <> "" And txtAttendance.Text <> "" And txtCA1.Text <> "" And txtCA2.Text <> "" And txtFinalExamResult.Text <> "" Then
Dim objRow3 = objDs.Tables("Student").Rows.Find(txtUpdateStudentID.Text.ToString)
'Editing each field value based on textboxes
objRow3.Item("FName") = txtUpdateFName.Text
objRow3.Item("SName") = txtUpdateSName.Text
objRow3.Item("Attendance") = txtUpdateAttendance.Text
objRow3.Item("CA1") = txtUpdateCA1.Text
objRow3.Item("CA2") = txtUpdateCA2.Text
objRow3.Item("FinalExam") = txtUpdateFinalExam.Text
objRow3.Item("OverallResult") = txtUpdateOverallGrade.Text
**'ERROR HERE STATING THIS ROW ALREADY BELONGS TO A TABLE**
objDs.Tables("Student").Rows.Add(objRow3)
objStudentDA.Update(objDs, "Student")
MsgBox("Record has been added to the IS2215 Database!")
Retrieve()
Else
MsgBox("Error: You must not leave any fields blank!")
End If
End Sub
Public Sub Retrieve()
objDs.Clear()
objStudentDA.FillSchema(objDs, SchemaType.Source, "Student")
objStudentDA.Fill(objDs, "Student")
cmbStudentFind.Items.Clear()
Dim i As Integer, strCurrentID As String
For i = 1 To objDs.Tables("Student").Rows.Count
strCurrentID = objDs.Tables("Student").Rows(i - 1).Item("ID")
cmbStudentFind.Items.Add(strCurrentID)
cmbUpdateStudentID.Items.Add(strCurrentID)
Next
cmbStudentFind.SelectedIndex = 0
cmbUpdateStudentID.SelectedIndex = 0
FillUpdateDetails()
End Sub
Public Sub FillUpdateDetails()
Dim objRow2 As DataRow
objRow2 = objDs.Tables("Student").Rows.Find(cmbUpdateStudentID.SelectedItem.ToString)
txtUpdateStudentID.Text = objRow2.Item("ID")
txtUpdateFName.Text = objRow2.Item("FName")
txtUpdateSName.Text = objRow2.Item("SName")
txtUpdateAttendance.Text = objRow2.Item("Attendance")
txtUpdateCA1.Text = objRow2.Item("CA1")
txtUpdateCA2.Text = objRow2.Item("CA2")
txtUpdateFinalExam.Text = objRow2.Item("FinalExam")
txtUpdateOverallGrade.Text = objRow2.Item("OverallResult")
End Sub
End Class
You need to execute CRUD against your Database. You will have a lot of problems trying to perform those operations against Access, as it tends to lock Tables when a Table is being accessed.
I would suggest you build a CRUD framework to "machine gun" the Insert, Update, and/or Delete operations into Access as you need.
Outside of that, you will loose a lot of hair in the process of trying to make it work.
For making inserts, you can stick with your current TextBox setup. For making updates, I would think a DataGridView would be a better way to go.
Something like this should work for you.
Imports System.Data.OleDb
Public Class Form1
Dim connetionString As String
Dim connection As OleDbConnection
Dim oledbAdapter As OleDbDataAdapter
Dim oledbCmdBuilder As OleDbCommandBuilder
Dim ds As New DataSet
Dim changes As DataSet
Dim i As Integer
Dim sql As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"
connection = New OleDbConnection(connetionString)
Sql = "select * from tblUsers"
Try
connection.Open()
oledbAdapter = New OleDbDataAdapter(Sql, connection)
oledbAdapter.Fill(ds)
DataGridView1.Data Source= ds.Tables(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
oledbCmdBuilder = New OleDbCommandBuilder(oledbAdapter)
changes = ds.GetChanges()
If changes IsNot Nothing Then
oledbAdapter.Update(ds.Tables(0))
End If
ds.AcceptChanges()
MsgBox("Save changes")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Or, you can stick with the TextBox concept, and change your setup slightly, as such.
str = "Journals SET JournalTitle=?, JournalText=? WHERE JournalDate=?"
cmd = New OleDbCommand(str, myConnection)
cmd.Parameters.AddWithValue("#jounalTitle", MyJournalTitle )
cmd.Parameters.AddWithValue("#journalText", MyJournalText)
cmd.Parameters.AddWithValue("#journalDate", DatePicked)
cmd.ExecuteNonQuery()
That methodology is much safer than the way you are doing it now. There are more details here.
How to update MS Access Database (vb.net)

Cant update a record in a database

I'm making a Homework/Revision program for my coursework. I'm following this tutorial http://www.homeandlearn.co.uk/NET/nets12p9.html on how to make a database but theres something wrong with the my update button (btnUpdate)
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
txtFirstName.Text = ds.Tables("Users").Rows(inc).Item(1) = txtFirstName.Text
txtSurname.Text = ds.Tables("Users").Rows(inc).Item(2) = txtSurname.Text
txtUsername.Text = ds.Tables("Users").Rows(inc).Item(3) = txtUsername.Text
txtPassword.Text = ds.Tables("Users").Rows(inc).Item(4) = txtPassword.Text
txtClass.Text = ds.Tables("Users").Rows(inc).Item(5) = txtClass.Text
txtAdmin.Text = ds.Tables("Users").Rows(inc).Item(6) = txtAdmin.Text
txtHWP.Text = ds.Tables("Users").Rows(inc).Item(7) = txtHWP.Text
MessageBox.Show("Data updated")
End Sub
Public Class AdminEditUsers 'this is the whole code
Dim MaxRows As Integer
Dim inc As Integer
Dim con As New OleDb.OleDbConnection 'THE CONNECTION OBJECT
Dim dbProvider As String 'HOLDS THE PROVIDER
Dim dbSource As String 'HOLDS THE DATA SOURCE
Dim MyDocumentsFolder As String 'HOLDS THEDOCUMENTS FOLDER
Dim TheDatabase As String 'HOLDS THE DATABASE NAME
Dim FullDatabasePath As String 'HOLDS THE DATABASE PATH
Dim ds As New DataSet 'HOLDS A DataSet OBJECT
Dim da As OleDb.OleDbDataAdapter 'HOLDS A DataAdapter OBJECT
Dim sql As String 'HOLDS A SQL STRING
Private Sub AdminEditUsers_load(sender As Object, e As EventArgs) Handles Me.Load
'SET UP THE PROVIDER
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
'SET THE DATABASE AND WHERE THE DATABASE IS
TheDatabase = "\Visual Studio 2015/NEW_database.accdb"
MyDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
FullDatabasePath = MyDocumentsFolder & TheDatabase
'SET THE DATA SOURCE
dbSource = "Data Source = " & FullDatabasePath
'SET THE CONNECTION STRING
con.ConnectionString = dbProvider & dbSource
'OPEN THE DATABASE
con.Open()
'STORE THE SQL STRING
sql = "Select * FROM tbl_user"
'PASS THE SQL STRING AND CONNECTION OBJECT TO THE DATA_ADAPTER
da = New OleDb.OleDbDataAdapter(sql, con)
'Fill the dataset with records from the database table
da.Fill(ds, "Users")
'CLOSE THE DATABASE
con.Close()
'Counts how many rows are in the table
MaxRows = ds.Tables("Users").Rows.Count
inc = -1
End Sub
Private Sub NavigateRecords()
txtFirstName.Text = ds.Tables("Users").Rows(inc).Item(1)
txtSurname.Text = ds.Tables("Users").Rows(inc).Item(2)
txtUsername.Text = ds.Tables("Users").Rows(inc).Item(3)
txtPassword.Text = ds.Tables("Users").Rows(inc).Item(4)
txtClass.Text = ds.Tables("Users").Rows(inc).Item(5)
txtAdmin.Text = ds.Tables("Users").Rows(inc).Item(6)
txtHWP.Text = ds.Tables("Users").Rows(inc).Item(7)
End Sub
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MessageBox.Show("No More Rows")
End If
End Sub
Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
ElseIf inc = -1 Then
MessageBox.Show("No Records Yet")
ElseIf inc = 0 Then
MessageBox.Show("First Record")
End If
End Sub
Private Sub btnLast_Click(sender As Object, e As EventArgs) Handles btnLast.Click
If inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If
End Sub
Private Sub btnFirst_Click(sender As Object, e As EventArgs) Handles btnFirst.Click
If inc <> 0 Then
inc = 0
NavigateRecords()
End If
End Sub
Private Sub btnAddNew_Click(sender As Object, e As EventArgs) Handles btnAddNew.Click
End Sub
Private Sub btnCommit_Click(sender As Object, e As EventArgs) Handles btnCommit.Click
End Sub
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
txtFirstName.Text = ds.Tables("Users").Rows(inc).Item(1) = txtFirstName.Text
txtSurname.Text = ds.Tables("Users").Rows(inc).Item(2) = txtSurname.Text
txtUsername.Text = ds.Tables("Users").Rows(inc).Item(3) = txtUsername.Text
txtPassword.Text = ds.Tables("Users").Rows(inc).Item(4) = txtPassword.Text
txtClass.Text = ds.Tables("Users").Rows(inc).Item(5) = txtClass.Text
txtAdmin.Text = ds.Tables("Users").Rows(inc).Item(6) = txtAdmin.Text
txtHWP.Text = ds.Tables("Users").Rows(inc).Item(7) = txtHWP.Text
MessageBox.Show("Data updated")
End Sub
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
End Sub
End Class
Where are you actually updating the database?
Read one more paragraph in that tutorial:
Close down your programme, then run it again. Click the Next Record button to move to the first record. It will still be "John Smith". The data you updated has been lost! So here, again, is why:
"Changes are made to the DataSet, and NOT to the Database"
The tutorial shows you how to persist those changes to the database:
da.Update(ds, "AddressBook")
Edit: It would also appear that you're making a mistake on lines like this:
txtFirstName.Text = ds.Tables("Users").Rows(inc).Item(1) = txtFirstName.Text
This may behave differently in different languages. In C# for example, I think that the result of an assignment is the value being assigned, so something like this might work. But in VB there are semantic contextual differences when using the same operator. The assignment operator (=) is also the comparison operator, depending on the context.
So I suspect that this line of code is comparing the latter two items, and assigning the result of the comparison (True or False) to the first item.
Stick with what the tutorial is showing you, just assign the value to the data:
ds.Tables("Users").Rows(inc).Item(1) = txtFirstName.Text
There's no need to also try to assign the value back to the text box where you got the value, since logically that value is already there.

Visual Studio 2010 form creation: fill an array with contents of a combobox

Trying to knock out a project that's hanging my code without re-writing the entire thing. In it, I just need to populate an array with the information already in the Names combobox in order to proceed. As I'm not using .NET, my options are limited.
(The end result)*Add a button named “btnShowBalance” displaying the text “ShowBalance.” Write code in its event handler asking the user to enter a client’s name (InputBox). Search the names array for the name entered. If the name is found, use its location to retrieve the matching balance from the balances array. Display the client’s name and balance if the client exists; otherwise, display a not-found message. ****
Public Class Form1
Dim Balances(7) As Decimal
Dim Names(7) As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cboNames.Items.Add("John One")
cboNames.Items.Add("Jack Two")
cboNames.Items.Add("John Three")
cboNames.Items.Add("Jack Four")
cboNames.Items.Add("John Five")
cboNames.Items.Add("Jack Six")
cboNames.Items.Add("John Seven")
cboNames.Items.Add("Jack Eight")
cboBalances.Items.Add("235.50")
cboBalances.Items.Add("78943.98")
cboBalances.Items.Add("230781.10")
cboBalances.Items.Add("78362.00")
cboBalances.Items.Add("12097.20")
cboBalances.Items.Add("89267.34")
cboBalances.Items.Add("34959.06")
cboBalances.Items.Add("559284.50")
For i = 0 To cboNames.Items.Count - 1
Names(i) = cboNames.Text
Next
For i = 0 To cboBalances.Items.Count - 1
Names(i) = cboBalances.SelectedItem
Next
End Sub
Private Sub btnShowBalance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowBalance.Click
Dim strResult As String
strResult = InputBox("Enter the name of the customer", "Balance Finder")
For i = 0 To Names.Length - 1
If strResult = Names(i) Then
MessageBox.Show(Names(i).ToString & " " & Balances(i).ToString)
End If
Next
End Sub
End Class

Resources