VB.NET - how receive datatable single value

Asked By kshama parashar
02-Sep-10 01:16 AM
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
  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
help
Difference between vb and vb.net Hai, I want to know about the main difference between vb and vb.net. • The greatest change in VB6 and VB.NET is of runtime environment. VB6 used the VB-Runtime while VB.NET uses the .Net Common Language Runtime (.Net CLR). The CLR is much better designed and
types? (B) What is concept of Boxing and Unboxing ? (B) What is the difference between VB.NET and C#? (I) what is the difference between System exceptions and Application exceptions? (I)What are different properties provided by Object-oriented systems? (B) How can we achieve inheritance in VB.NET? (I) what are abstract classes? (B) What is a Interface? (A) What is difference between prevent a class from overriding? (I) what is the use of “Must inherit” keyword in VB.NET? (I) Do interface have accessibility modifier. (A) What are similarities between Class and structure? (A between Class and structure’s? (B) What does virtual keyword mean? (B) What are shared (VB.NET) / Static(C#) variables? (B) What is Dispose method in .NET? (B) What is the use
Differences for vb.net and c# with Example Dear all Differences for vb.net and c# with Example., plz give the solutions Thanks to all Hi See the bellow comparission :: This comparission is with syntax and example. . . Comments VB.NET 'Single line only Rem Single line only C# / / Single line / * Multiple line * / / / / XML comments on single line / * * XML comments on multiple lines * / Program Structure VB.NET Imports System Namespace MyNameSpace Class HelloWorld 'Entry point which delegates to C-style main Private
diffrence what 's diif b / w vb.net & c#.net refer the link, it explan u Syntax Differences and Managed and Unmanaged code in earlier versions. You have lot of articles to find out the differences b / w VB.NET & C#.NET depending on various aspects. Iam providing a few, which were discussed in different aspects. Go through them. http: / / support.microsoft.com / kb / 308470 some key syntactical differences between VB.NET (version 2) and C#. http: / / www.harding.edu / fmccown / vbnet_csharp_comparison.html Choosing between C# and VB.NET: http: / / www.dnjonline.com / article.aspx?ID = mar05_vbvscsharp Complete Comparison for VB.NET and C