object reference not set to an instance of an object Inserting database sql array - vb.net

How can i insert array textbox in database?I have to save each newboxes in access and it should be in different row..It has an error object reference not set to an instance of an object when saving the data
Public Class Form1
Dim boxes As New List(Of TextBox)
Dim combo As New List(Of ComboBox)
Private Sub Addbuttons(buttonCount As Integer)
Dim newbox As TextBox Dim newcombo As ComboBox
For i As Integer = 1 To buttonCount
newbox = New TextBox
newbox.Size = New Drawing.Size(575, 35)
newbox.Location = New Drawing.Point(10, 10 + 35 * (i - 1))
newbox.Name = "TextBox" & i
newbox.Text = newbox.Name
'connect it to a handler, save a reference to the array and add it to the form controls
boxes.Add(newbox)
Me.Controls.Add(newbox)
Next For i As Integer = 1 To buttonCount
newcombo = New ComboBox
newcombo.Size = New Drawing.Size(57, 20)
newcombo.Location = New Drawing.Point(864, 531 + 70 * (i - 1))
combo.Add(newcombo)
Me.Controls.Add(newcombo)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Addbuttons(Val(TextBox1.Text))
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
addbuyer()
End Sub
Private Sub addbuyer()
Dim newbox As TextBox
Try
datab = " Insert INTO sample (sample1,sample2) values ( '" & newbox.Text & "','" & newqty.Text & "')"
connDB()
cmd = New OleDbCommand(datab, conn)
Dim i As Integer
i = cmd.ExecuteNonQuery
If i > 0 Then
' MsgBox("Added SUccesfully", MsgBoxStyle.Information, "Confirmation")
Else
MsgBox("Failed Adding", MsgBoxStyle.Information, "Alert!")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub
End Class

In addbuyer, Dim newbox As TextBox is nothing and that's the cause of the error.
You added all the textbox controls to boxes so you need to loop thru that when you insert into the DB. One way to do it is by looping and passing each textbox by reference:
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
For Each t As TextBox In boxes
addbuyer(t)
Next
End Sub
Private Sub addbuyer(ByRef newbox As TextBox)
Try
datab = " Insert INTO sample (sample1) values ( '" & newbox.Text & "')"
connDB()
cmd = New OleDbCommand(datab, conn)
Dim i As Integer
i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Added SUccesfully", MsgBoxStyle.Information, "Confirmation")
Else
MsgBox("Failed Adding", MsgBoxStyle.Information, "Alert!")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub

Related

DataGridView refreshing fixed position in row filter textbox in vb.net

I want when filtering rows in the textbox then the database is updated from other applications then I do a refresh I want the datagridview that I filter in the textbox in a fixed position and also when selected in the combobox as well. Maybe my code isn't perfect. So there may be the best solution.
Thanks
VIEW DATAGRIDVIEW
Public Class Form1
Dim Path As String = Application.StartupPath()
Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
Private WithEvents dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.PopulateComboBox()
Me.PopulateDataGridView()
Me.clearfiltercombobox()
End Sub
Private Sub PopulateDataGridView()
Try
Dim query = "select ITM,ART,QTY FROM EXAMPLE WHERE QTY > 0 AND BRAND = #BRAND"
Using con As OleDbConnection = New OleDbConnection(cn)
Using cmd As OleDbCommand = New OleDbCommand(query, con)
cmd.Parameters.AddWithValue("#BRAND", ComboBox1.SelectedValue)
Using adapter As New OleDbDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
adapter.Fill(dt)
Me.DataGridView1.DataSource = dt
End Using
End Using
End Using
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
End Try
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Try
CType(DataGridView1.DataSource, DataTable).DefaultView.RowFilter = String.Format("ITM LIKE '%{0}%' OR ITM LIKE '%{0}%'", TextBox1.Text)
Catch ex As Exception
MsgBox("No match found")
End Try
End Sub
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
Me.TextBox1.Text = ""
Me.PopulateDataGridView()
End Sub
Private Sub PopulateComboBox()
Dim query As String = "SELECT DISTINCT BRAND FROM EXAMPLE WHERE QTY > 0"
Try
Using con As OleDbConnection = New OleDbConnection(cn)
Using sda As OleDbDataAdapter = New OleDbDataAdapter(query, con)
'Fill the DataTable with records from Table.
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
'Insert the Default Item to DataTable.
Dim row As DataRow = dt.NewRow()
row(0) = ""
dt.Rows.InsertAt(row, 0)
'Assign DataTable as DataSource.
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "BRAND"
ComboBox1.ValueMember = "BRAND"
End Using
End Using
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
End Try
End Sub
Private Sub clearfiltercombobox()
Try
ComboBox1.ResetText()
TextBox1.Text = ""
Dim query = "select ITM,ART,QTY FROM EXAMPLE WHERE QTY > 0"
Using con As OleDbConnection = New OleDbConnection(cn)
Using cmd As OleDbCommand = New OleDbCommand(query, con)
Using adapter As New OleDbDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
adapter.Fill(dt)
Me.DataGridView1.DataSource = dt
End Using
End Using
End Using
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
End Try
End Sub
Private Sub Refreshonly_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Refreshonly.Click
Me.clearfiltercombobox()
DataGridView1.Refresh()
End Sub
Private Sub clearall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clearall.Click
Me.clearfiltercombobox()
End Sub
End Class

HOW TO SOLVE There is no row at position 2 VB.NET using sqldatabase

Private Sub Charges()
Dim Query As String
Query = "Select * from Charges where DOctype='" & comboBoxTranType.Text & "'"
Dim cmd As New SqlCommand(Query, con)
con.Open()
Dim dataAdapter As New SqlDataAdapter(Query, con)
Dim dt As New DataTable
dataAdapter.Fill(dt)
dataAdapter.Dispose()
If dt.Rows.Count > 0 Then
LabelV001.Text = dt.Rows(0).Item("Head").ToString()
LabelV002.Text = dt.Rows(1).Item("Head").ToString()
LabelV003.Text = dt.Rows(2).Item("Head").ToString()
End If
If dt.Rows.Count > 0 Then
LabelFIELD1.Text = dt.Rows(0).Item("Equation").ToString()
LabelFIELD2.Text = dt.Rows(1).Item("Equation").ToString()
LabelFIELD3.Text = dt.Rows(2).Item("Equation").ToString()
End If
con.Close()
End Sub
SIR WITH YOUR HELP I GOT THE RESULT BEFORE, BUT CAUSE OF ERROR FOR FIELDTEXT3 i.e There is no row at position 2, equation 3 cannot be calculated, pls help me out,
Not sure why they were so quick to close your new question...I was building an answer for it.
Click on Project --> Add Reference
Switch to the COM option
Select the "Microsoft Script Control 1.0" entry and click OK.
Now you can use code like below, creating code for textCharges1 --> V001 through textCharges25 --> V025:
Public Class Form1
Private SC As New MSScriptControl.ScriptControl
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SC.Language = "VBScript"
Dim ctl As Control
Dim ctlName, functionBody As String
functionBody = "Function {0}()" & vbCrLf & vbTab & "{0} = CDbl({1}.Text)" & vbCrLf & "End Function"
For i As Integer = 1 To 25
ctlName = "textCharges" & i
ctl = Me.Controls.Find(ctlName, True).FirstOrDefault
If Not IsNothing(ctl) Then
SC.AddObject(ctlName, ctl, True)
SC.AddCode(String.Format(functionBody, "V" & i.ToString("000"), ctlName))
End If
Next
LABELFIELD2.Text = "V001*V002/100"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim result = SC.Eval(LABELFIELD2.Text)
lblResult.Text = result
Catch ex As Exception
lblResult.Text = "{Error}"
End Try
End Sub
End Class
Running example:

how can i fix this error=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

I have a gridview when i click the column of the dataGridview the problem show
"error=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index""
how can i fix this? please help
this is the whole code.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'construct dataGridview
DataGridView1.ColumnCount = 4
DataGridView1.Columns(0).Name = "name"
DataGridView1.Columns(1).Name = "position"
DataGridView1.Columns(2).Name = "team"
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullColumnSelect
End Sub
Private Sub Populate(name As String, pos As String, team As String)
Dim row As String() = New String() {name, pos, team}
DataGridView1.Rows.Add(row)
End Sub
Private Sub Retrieve()
DataGridView1.Rows.Clear()
Dim sql As String = "SELECT * FROM peopleTB"
cmd = New OleDbCommand(sql, con)
Try
con.Open()
adapter = New OleDbDataAdapter(cmd)
adapter.fill(dt)
'fill dgview
For Each row In dt.Rows
Populate(row(1), row(2), row(3))
Next
con.Close()
dt.Rows.Clear()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
End Sub
Private Sub Cleartxt()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
'update db and dg
Private Sub UpdateDG(name As String)
Dim sql As String = "UPDATE peopleTB Set N ='" + TextBox1.Text + "',P='" + TextBox2.Text + "',T='" + TextBox3.Text + "'WHERE N= '" + name + "'"
'OPEN CON
Try
con.Open()
adapter.updateCommand = con.CreateCommand()
adapter.updateCommand.commandtext = sql
If adapter.updateCommand.executenonquery() > 0 Then
MsgBox("Success updated")
Cleartxt()
End If
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
End Sub
Private Sub DataGridView1_MouseClick(sender As Object, e As MouseEventArgs) Handles DataGridView1.MouseClick
Dim name As String = DataGridView1.SelectedRows(0).Cells(0).Value
Dim position As String = DataGridView1.SelectedRows(0).Cells(1).Value
Dim team As String = DataGridView1.SelectedRows(0).Cells(2).Value
TextBox1.Text = name
TextBox2.Text = position
TextBox3.Text = team
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim name As String = DataGridView1.SelectedRows(0).Cells(0).Value
UpdateDG(name)
End Sub
Im using ms access

Insert array of two dims as list of textbox and combobox in MS Access

How can I insert array textbox and combobox in database? I have to save each newboxes and newcombo in Access and it should be in a different row. It has an error object reference not set to an instance of an object when saving the data
Imports System.Data.OleDb
Imports System.IO
Public Class Form1
Dim form As New Form
Dim boxes As New List(Of TextBox)
Dim combo As New List(Of ComboBox)
Private Sub Addbuttons(ByVal buttonCount As Integer)
Dim newbox As TextBox
Dim newcombo As ComboBox
For i As Integer = 1 To buttonCount
newbox = New TextBox
newbox.Size = New Drawing.Size(533, 50)
newbox.Location = New Drawing.Point(227, 531 + 70 * (i - 1))
newbox.Name = ""
newbox.Text = newbox.Name
'connect it to a handler, save a reference to the array and add it to the form controls
boxes.Add(newbox)
Me.Controls.Add(newbox)
Next
For i As Integer = 1 To buttonCount
newcombo = New ComboBox
newcombo.Size = New Drawing.Size(57, 20)
newcombo.Location = New Drawing.Point(864, 531 + 70 * (i - 1))
combo.Add(newcombo)
Me.Controls.Add(newcombo)
Next
End Sub
'Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
'End Sub
'Private Sub btnitem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnitem.Click
' Addbuttons(Val(txtitem.Text))
'End Sub
Private Sub loaduom(ByRef newcombo As ComboBox)
Try
datab = "Select uom from uom"
connDB()
cmd = New OleDbCommand(datab, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
newcombo.Items.Clear()
Do While dr.Read = True
' txtdepartadd.Items.Add(dr("Departmentname"))
newcombo.Items.Add(dr(0))
Loop
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub
Private Sub loading()
For Each uomlo As ComboBox In combo
loaduom(uomlo)
Next
End Sub
'Private Sub loaduom()
' Throw New NotImplementedException
'End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim msgboxresponse As MsgBoxResult
msgboxresponse = MsgBox("Are You Sure of the number of Item you choose?Please Check Again", _
MsgBoxStyle.Question + MsgBoxStyle.YesNo, Me.Text)
If msgboxresponse <> MsgBoxResult.Yes Then
Else
Addbuttons(Val(txtitem.Text))
txtitem.Enabled = False
Button1.Enabled = False
loading()
loadstat()
Return
End If
End Sub
Private Sub addbuyer(ByRef newbox As TextBox, ByRef newcombo As ComboBox)
'Dim newbox As TextBox
'Dim newcombo as combobox
Try
datab = " Insert INTO sample (sample1,sample2) values ( '" & newbox.Text & "','" & newcombo.Text & "')"
connDB()
cmd = New OleDbCommand(datab, conn)
Dim i As Integer
i = cmd.ExecuteNonQuery
If i > 0 Then
MsgBox("Added SUccesfully", MsgBoxStyle.Information, "Confirmation")
Else
MsgBox("Failed Adding", MsgBoxStyle.Information, "Alert!")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim buttonCount As Integer = Val(TextBox1.Text)
'start from 0 because it's 0-based index
For i As Integer = 0 To buttonCount - 1
addbuyer(boxes(i), combo(i))
Next
End Sub
End Class
Here's how to do it based on your current code
In Button2_Click:
1) Get the total # of controls
2) loop and call addbuyer passing the controls by reference
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim buttonCount As Integer = Val(txtitem.Text)
'start from 0 because it's 0-based index
For i As Integer = 0 To buttonCount - 1
addbuyer(boxes(i), combo(i))
Next
End Sub
In addbuyer:
1) change ByRef newbox As RichTextBox to ByRef newbox As TextBox
2) comment out (or delete) the first two lines, they aren't needed
Private Sub addbuyer(ByRef newbox As TextBox, ByRef newcombo As ComboBox)
'Dim newbox As TextBox
'Dim newcombo as combobox
Try
datab = " Insert INTO sample (sample1,sample2) values ( '" & newbox.Text & "','" & newcon.Text & "')"
connDB()
cmd = New OleDbCommand(datab, conn)
Dim i As Integer
i = cmd.ExecuteNonQuery
If i > 0 Then
' MsgBox("Added SUccesfully", MsgBoxStyle.Information, "Confirmation")
Else
MsgBox("Failed Adding", MsgBoxStyle.Information, "Alert!")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub

Auto-fill textbox on a dialog form, from a Datagridview on the original form, vb.net 2013

I am currently working in windows form applications using vb.net 2013. I have two forms, we can call them form1 and form 2 for now. Form1 has a datagridview with a checkbox column that the end user will click to open form2 as a dialog form. Once form2 opens I want it to automatically load and fill two text boxes that have information from corresponding columns from the original DGV. In short, the DGV on form1 has 3 columns; JobNumber, LineNumber, and the checkbox. The end user will click the checkbox to bring up form2 and I want the Jobnumber and Linenumber to automaticaly fill into two textboxes on form2. Here is my code from form1.
'assembly dialog result form
dr = f.ShowDialog
If dr = Windows.Forms.DialogResult.OK Then
'dim y as job string
Dim Y As String = DataGridOrdered.Rows(e.RowIndex).Cells(3).Value
'open connection
Using conn1 As New SqlConnection(connstring)
conn1.Open()
Using comm1 As SqlCommand = New SqlCommand("UPDATE Production.dbo.tblFCOrdered SET Complete = 1, RackIn = 1 WHERE JobNumber = '" & Y & "'", conn1)
comm1.ExecuteNonQuery()
conn1.Close()
End Using
End Using
Call DGVOrderedRefresh()
ElseIf dr = Windows.Forms.DialogResult.Yes Then
'dim M as job string
Dim M As String = DataGridOrdered.Rows(e.RowIndex).Cells(3).Value
'open connection
Using conn1 As New SqlConnection(connstring)
conn1.Open()
Using comm1 As SqlCommand = New SqlCommand("UPDATE Production.dbo.tblFCOrdered SET Complete = 1, RackIn = 1 WHERE JobNumber = '" & M & "'", conn1)
comm1.ExecuteNonQuery()
conn1.Close()
End Using
End Using
Call DGVOrderedRefresh()
ElseIf dr = Windows.Forms.DialogResult.Cancel Then
'refresh datagridview ordered
Call DGVOrderedRefresh()
End If
ElseIf e.ColumnIndex = 0 Then
'fail safe to make sure the header is not clicked
If e.RowIndex = -1 Then
Exit Sub
End If
The code for my dialog is as follows
Imports System.Data
Imports System.Data.SqlClient
Public Class BuildName
' Dim connstring As String = "DATA SOURCE = BNSigma\CORE; integrated security = true"
Dim connstring As String = "DATA SOURCE = BNSigma\TEST; integrated security = true"
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
End Sub
Private Sub BuildName_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ds As New DataTable
Try
'load name combo box
Using conn1 As New SqlConnection(connstring)
conn1.Open()
Using comm1 As SqlCommand = New SqlCommand("SELECT Name FROM Production.dbo.FCNames", conn1)
Dim adapater As New SqlDataAdapter
adapater.SelectCommand = comm1
adapater.Fill(ds)
adapater.Dispose()
conn1.Close()
CBName.DataSource = ds
CBName.DisplayMember = "Name"
CBName.ValueMember = "Name"
End Using
End Using
Catch ex As Exception
MsgBox("Error loading name List, please contact a mfg. Engr.!")
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Update built by name
Dim v As Object = TBFloor.Text
Dim G As Object = TBLine.Text
Dim O As Object = TBJobNumber.Text
Try
Using conn1 As New SqlConnection(connstring)
conn1.Open()
Using comm1 As SqlCommand = New SqlCommand("UPDATE Production.dbo.tblFCOrdered SET BuiltBy = #Name Where JobNumber = '" & O & "'", conn1)
comm1.Parameters.AddWithValue("#Name", CBName.Text)
comm1.ExecuteNonQuery()
conn1.Close()
End Using
End Using
Catch ex As Exception
MsgBox("Error updating Ordered table, please contact a MFG. ENGR.!")
MsgBox(ex.ToString)
End Try
End Sub
End Class
UPDATED CODE FOR VALTER
Form1 code
Public row_Index As Integer = 0
Private Sub DataGridOrdered_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles DataGridOrdered.CurrentCellDirtyStateChanged
If DataGridOrdered.IsCurrentCellDirty Then
DataGridOrdered.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
Private Sub DataGridOrdered_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridOrdered.CellValueChanged
If DataGridOrdered.Columns(e.ColumnIndex).Name = 9 Then
Dim checkCell As DataGridViewCheckBoxCell = CType(DataGridOrdered.Rows(e.RowIndex).Cells(9), DataGridViewCheckBoxCell)
If CType(checkCell.Value, [Boolean]) = True Then
row_Index = e.RowIndex
BuildName.ShowDialog(Me)
End If
End If
End Sub
Form 2 code
Private Sub BuildName_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim value1 As Object = FormOrdered.DataGridOrdered.Rows(FormOrdered.row_Index).Cells(3).Value
Dim value2 As Object = FormOrdered.DataGridOrdered.Rows(FormOrdered.row_Index).Cells(4).Value
TBJobNumber.Text = CType(value1, String)
TBFloor.Text = CType(value2, String)
In your form1 add:
Public Row_Index As Integer = 0 //use a simple variable
Sub datagridOrdered_CurrentCellDirtyStateChanged( _
ByVal sender As Object, ByVal e As EventArgs) _
Handles datagridOrdered.CurrentCellDirtyStateChanged
If datagridOrdered.IsCurrentCellDirty Then
datagridOrdered.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
Private Sub datagridOrdered_CellValueChanged(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles datagridOrdered.CellValueChanged
If datagridOrdered.Columns(e.ColumnIndex).Name = "Assemble" Then //<- here
Dim checkCell As DataGridViewCheckBoxCell = _
CType(datagridOrdered.Rows(e.RowIndex).Cells(2), _ //<- here
DataGridViewCheckBoxCell)
If CType(checkCell.Value, [Boolean]) = True Then
//RowIndex = e.RowIndex you dont need this
Row_Index = e.RowIndex
BuildName.ShowDialog(Me)
End If
End If
End Sub
//Nor this
//Private _count As Integer
//Public Property RowIndex() As Integer
//Get
//Return _count
//End Get
//Set(value As Integer)
//_count = value
//End Set
//End Property
And in dialog load event use Form1.Row_Index instead:
Private Sub BuildName_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim value1 As Object = FormOrdered.datagridOrdered.Rows(Form1.Row_Index).Cells(0).Value //<- here
Dim value2 As Object = FormOrdered.datagridOrdered.Rows(Form1.Row_Index).Cells(1).Value //<- here
TBJobNumber.Text = CType(value1, String)
TBFloor.Text = CType(value2, String)
...
...
End Sub
or add a module and add the Row_Index there. You can use it then as is
Private Sub BuildName_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim value1 As Object = FormOrdered.DataGridView1.Rows(Row_Index).Cells(0).Value
Dim value2 As Object = FormOrdered.DataGridView1.Rows(Row_Index).Cells(1).Value
TBJobNumber.Text = CType(value1, String)
TBFloor.Text = CType(value2, String)
...
...
End Sub