How we can create dynamic variable and store value

How we can create dynamic variable and store value. I am looking for this solution
eg I have db query
select a,b,c from tablename I will get output in datatable now I want to store
var a = data of a in datatable
var b = data of a in datatable
var c = data of c in datatable
in future if we pass query sql query select a,b,c,d from tablename
this will give
var a = data of a in datatable
var b = data of a in datatable
var c = data of c in datatable
var d = data of d in datatable
these variable I want to create dynamic as per sql coulumn

Hi @Aditya10989

Try this approach-

Dim dt As DataTable
Dim columnDict As New Dictionary(Of String, Object)()

For Each column As DataColumn In dt.Columns
columnDict(column.ColumnName) = dt.Rows(0)(column.ColumnName)
Next

Dim a As Object = columnDict(“a”)
Dim b As Object = columnDict(“b”)
Dim c As Object = columnDict(“c”)

Thanks!!

I have tried one method.I guess its work but I have stuck in one point by using columname.list I will get value in int. Now I want this will create different variable as per count
eg columname.list = 4
this will create 4 different variable
var1
var2
var3
var4

@Aditya10989

You cannot create variable dynamically…

But what you can try is to use dictionary to have them…

you can create a dictionary and initialize it with Dictionary(Of String, String) - This creates dictionary of key and value both as strings

and to assign value use dict("Var1") = "value of var1"

Similarly you can create others… to access them simply use dict("Var1") to convert to string use .ToString

Hope this helps

cheers