how receive datatable single value

Asked By kshama parashar
02-Sep-10 01:16 AM
Earn up to 0 extra points for answering this tough question.
i want to receive datatable row value in a variable 
my code is :
 Dim i, j As Integer
        Dim con As New SqlConnection
        Dim cstring As String
        Dim cmd As New SqlCommand
        cstring = "data source=c7; initial catalog=vbdatabase; integrated security=true"
        con.ConnectionString = cstring
        con.Open()
        cmd = New SqlCommand("select id from sale")
        Dim adp As New SqlDataAdapter
        adp = New SqlDataAdapter
        cmd.Connection = con
        adp.SelectCommand = cmd
        Dim dt As New DataTable
        dt = New DataTable
        adp.Fill(dt)
        ComboBox1.DataSource = dt
        ComboBox1.DisplayMember = "name1"
        ComboBox1.ValueMember = "ID"

        Dim n As Integer
        n = ComboBox1.Items.Count
        'n = n - 1
        For i = 1 To 10
            'j = dt.Rows(n)(0)
            If i = dt.Rows(n - 1)("id").ToString() Then
                ComboBox2.Items.Remove(i)
            Else
                ComboBox2.Items.Add(i)
            End If

        Next

  re: how receive datatable single value

Venkat K replied to kshama parashar
02-Sep-10 01:59 AM
You can iterate through the database columns and then rows to store the vlaues in the variables:

Ex:

The cellData should of type object which has the same variable that a datarow exists.
Dim tbl As New DataTable()
For Each row As DataRow In tbl.Rows
  For Each col As DataColumn In tbl.Columns
	Dim cellData As Object = row(col)
  Next
Next





Thanks,
Create New Account