Thursday, 12 June 2014

Two Query one No column in VB.net

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=pramod;Integrated Security=True;")

        Dim ds As New DataSet
        Dim dsa As New DataSet
        Dim dr As New SqlDataAdapter("SELECT count(name)+ 1+ROW_NUMBER()  OVER (ORDER BY name) AS id ,name FROM test1 group by name; SELECT ROW_NUMBER()  OVER (ORDER BY lastname) AS id, lastname FROM test2; ", con)

        dr.Fill(ds)

        Dim i As Integer = 0
        Dim table As DataTable = ds.Tables(0)
        table.Columns.Add(New DataColumn("no", GetType(Integer)))
        Dim rowcount As Integer = table.Rows.Count
        Dim k As Integer = 1
        While (i < rowcount)
            table.Rows(i)("no") = k
            i = i + 1
            k = k + 1

        End While

        GridView1.DataSource = table
        GridView1.DataBind()
        Dim j As Integer = 0
        Dim tablea As DataTable = ds.Tables(1)
        tablea.Columns.Add(New DataColumn("no", GetType(Integer)))
        rowcount = tablea.Rows.Count
        While (j < rowcount)
            tablea.Rows(j)("no") = k
            k = k + 1
            j = j + 1
        End While
        GridView2.DataSource = tablea
        GridView2.DataBind()
       

    End Sub

No comments:

Post a Comment