I am not able to get a sub that I am working on to update a string with a value from a database. I have designed the sub to be dynamic to object type and it works with all other objects.
Is it not possible to update strings like this?
What I have tried:
I have created the following sub to act as the filler for various objects in my application based on an sql database.
Public Sub SQL_Object_Fill(sp As String, Params As Array, Values As Array, Objs As Array, Cols As Array, Optional type As String = Nothing)
Dim cmd As New SqlCommand()
Dim dr As SqlDataReader
cmd.Connection = cn
cmd.CommandText = sp
cmd.CommandType = CommandType.StoredProcedure
For Each Param As String In Params
cmd.Parameters.Add(New SqlParameter(Param, Values(Array.IndexOf(Params, Param))))
Next
cn.Open()
dr = cmd.ExecuteReader()
If dr.HasRows Then
While (dr.Read())
For Each obj As Object In Objs
If obj.GetType() Is GetType(System.String) Then
obj = (dr(Cols(Array.IndexOf(Objs, obj)))).ToString()
MsgBox(obj)
ElseIf obj.GetType() Is GetType(System.Windows.Forms.ListBox) Then
obj.Items.Add(dr(Cols(Array.IndexOf(Objs, obj)).ToString()))
ElseIf obj.GetType() Is GetType(MetroFramework.Controls.MetroTextBox) Or obj.GetType() Is GetType(MetroFramework.Controls.MetroTile) Then
obj.Text = (dr(Cols(Array.IndexOf(Objs, obj)).ToString()))
End If
Next
End While
End If
cn.Close()
End Sub
This has been working so far but I am now at a stage where I need to call the function to set the value of a string. Code below:
Dim Email As String = ""
SQL_Object_Fill(sp:="[Misc].[Email_Fields]", Params:={"@id", "@Type"}, Values:={Main.id, Type}, Objs:={Email}, Cols:={"Email"})
MsgBox(Email)
I have put a msgbox both in the function and after when I am calling it. It comes up with the expected value from the message box within the function but not in the one after the function is called?
What am I doing wrong? All of the other object types work perfectly.
For some reason this is not assigning my object to the value of the column in the stored procedure. I have put a msg box in the