Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to get results from a select query and view them in VB.net in a form??

how to get results from a select query and view them in VB.net in a form??

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasetutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    drmzunlimited
    wrote on last edited by
    #1

    i think if the query is like sCategory = "SELECT CATEGORY.CATEGORY FROM CATEGORY ORDER BY CATEGORY.CATEGORY" in this the return type is a string and I could bind the output to a textbox and to a combobox. now if the query is like sCategory = "SELECT CATEGORY.* FROM CATEGORY" then how to view the results ?? I think Datagrid should be used....well not sure plz tell me how to bind and get the output in a datagrid .... and do tell me how to get a value from a particular cell to use it in another query. ==thnx waiting for a reply

    P 1 Reply Last reply
    0
    • D drmzunlimited

      i think if the query is like sCategory = "SELECT CATEGORY.CATEGORY FROM CATEGORY ORDER BY CATEGORY.CATEGORY" in this the return type is a string and I could bind the output to a textbox and to a combobox. now if the query is like sCategory = "SELECT CATEGORY.* FROM CATEGORY" then how to view the results ?? I think Datagrid should be used....well not sure plz tell me how to bind and get the output in a datagrid .... and do tell me how to get a value from a particular cell to use it in another query. ==thnx waiting for a reply

      P Offline
      P Offline
      Peet Schultz
      wrote on last edited by
      #2

      In this example I am using the datadapter, as you can bind the whole resultset to the grid in one command, with the datareader you have to loop through the resultset. Dim oConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection() Dim oCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand() Dim oDataTableResources As Data.DataTable = New Data.DataTable() Dim oDataTableSites As Data.DataTable = New Data.DataTable() Dim oDataAdapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter() Dim sSiteName As String Dim sResourceName As String Const iDayLength As Integer = 86400 sSQL = "Select * from Category" gsConnectString = " Initial Catalog=" & UCase(Trim(Me.txtDB.Text)) & _ ";Data Source=" & UCase(Trim(Me.txtSVR.Text)) & _ ";User ID=" & UCase(Trim(Me.txtUID.Text)) & _ ";Password=" & Trim(Me.txtPWD.Text) & ";" oConnection.ConnectionString = gsConnectString Try oConnection.Open() Catch o As System.Exception MsgBox(o.Message, MsgBoxStyle.Critical, gsMessageBoxHeader) Me.Cursor = Cursors.Default Exit Sub End Try Try oCommand.Connection = oConnection oCommand.CommandText = sSQL oDataAdapter.SelectCommand = oCommand 'fill the data adapter oDataAdapter.Fill(oDataTableResources) 'bind to the datagrid dbgrdDataGrid.DataSource = oDataTableResources dbgrdDataGrid.ParentRowsVisible = False Catch o As System.Exception MsgBox(o.Message) Me.Cursor = Cursors.Default End Try I do not have any code of getting a specific cell from the grid. I am sure you will be able to find samples on the web. YASP

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups