datagrid view help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

datagrid view help

sukysuky Posts: 2Member
hi everyone. i just joined.

i have run into a problem while doing a search program. please help me.

i am trying to search a database and return the results in a datagrid view. my webform contains a text box txtsearch and a button btnSearch and a datagrid view grdoutput. the problem is i can not get anything to display. here is the code

[code]Imports System.Data
Imports System.data.OleDb

Partial Class search
Inherits System.Web.UI.Page
Dim myDataTable As New DataTable

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim strSQL As String

strSQL = "select Pin from Credentials where Gpa > " & txtSearch.Text & ""

Dim conConnection As New OleDbConnection
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" & System.AppDomain.CurrentDomain.BaseDirectory() & "App_Datash.mdb"
conConnection.Open()

Dim myDataAdapter As New OleDbDataAdapter(strSQL, conConnection)

myDataAdapter.Fill(myDataTable)
grdoutput.DataSource = myDataTable

conConnection.Close()
myDataAdapter.Dispose()
End Sub

End Class[/code]

can someone please help?




Comments

  • sukysuky Posts: 2Member
    no one willing to share advice? :(
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Hey, Just so you know, this is a VB.Net forum and your question is more related to ASP.Net... Here's a possible solution:

    You didn't call the DataBind() routine that populates the object with all of the data you just set to the dataSource. Try this code, read the comments as well:

    [code]

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    'Make sure you are not declaring global variables in ASP.Net
    'Global variables are global across all Sessions accessing the page
    'and very odd bugs will occur once the applications goes into
    'use or beta-testing...

    'If you need a global variable, use Session variables
    Dim myDataTable As New DataTable
    Dim strSQL As String

    strSQL = "select Pin from Credentials where Gpa > " & txtSearch.Text & ""

    Dim conConnection As New OleDbConnection
    conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" & System.AppDomain.CurrentDomain.BaseDirectory() & "App_Datash.mdb"
    conConnection.Open()

    Dim myDataAdapter As New OleDbDataAdapter(strSQL, conConnection)

    myDataAdapter.Fill(myDataTable)
    grdoutput.DataSource = myDataTable
    'This routine will cause grdoutput to fille in it's row data
    'from the data in DataSource
    grdoutput.DataBind()

    conConnection.Close()
    myDataAdapter.Dispose()
    End Sub

    [/code]
Sign In or Register to comment.