Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb to asp.net

Status
Not open for further replies.

takwirira

Programmer
Mar 6, 2007
23
GB
I am trying to make an asp.net webpage that does exactly the same thing as my application. This application searches a database for all names beginnig with the letter T and populated a gridview. on trying to use the same code in asp it wont work. could i please have some help in converting it such that i can use it in asp.net for my website

Imports System.Data
Imports System.Data.OleDb
Public Class Form1

' some code here
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the ' RunnersdbDataSet.Runners' table. You can move, or remove it, as needed.
Me.RunnersTableAdapter.Fill(Me.RunnersdbDataSet.Ru nners)
' create a connection string
Dim connString As String = "Provider= Microsoft.Jet.OLEDB.4.0;Data Source=C:\runnersdb.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
' create a data adapter
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select Name from Runners WHERE Name LIKE 'T%'", myConnection)
' create a new dataset
Dim ds As DataSet = New DataSet
' fill dataset
da.Fill(ds, "Runners")
' write dataset contents to an xml file by calling WriteXml method
' Attach DataSet to DataGrid
DataGridView1.DataSource = ds.Tables(0).DefaultView

End Sub
End Class
 
i was hoping the ode above could be converted into that
 
Appart from the fact that the datagridview doesn't exist in ASP.Net all the other code should work just use a different control.

And it doesn't work isn't being very helpfull.
What doesn't work? What have you tried?

Christiaan Baes
Belgium

My Blog
 
I copied the code exactly as above, and created a new website in VB2005 I have the text box, search button and gridview in asp.net.This is how the code looks now

Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

'TODO: This line of code loads data into the 'RunnersdbDataSet.Runners' table. You can move, or remove it, as needed.
Me.RunnersTableAdapter.Fill(Me.RunnersdbDataSet.Runners)
' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("runnersdb.mdb")
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
' create a data adapter
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select Name from Runners WHERE Name LIKE 'T%'", myConnection)
' create a new dataset
Dim ds As DataSet = New DataSet
' fill dataset
da.Fill(ds, "Runners")
' write dataset contents to an xml file by calling WriteXml method
' Attach DataSet to DataGrid
GridView1.DataSource = ds.Tables(0).DefaultView

End Sub


End Class

The only error is highlighted under

Me.RunnersTableAdapter.Fill(Me.RunnersdbDataSet.Runners)

it says RunnersbdTableAdapater and RunnersdbDataSet.Runners is not a member of _default. Im guessing its because I cant use Me. to refer to the page and im not sure what contruct to use there

Sorry for inadequate information earlier
 
I ended up with this code here, it does not produce any errors on run time but when i click the search button it does not do anything i.e. populate the gridview box with names starting with T

Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

'TODO: This line of code loads data into the 'RunnersdbDataSet.Runners' table. You can move, or remove it, as needed.
'Me.RunnersTableAdapter.Fill(Me.RunnersdbDataSet.Runners)
' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("runnersdb.mdb")
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
' create a data adapter
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select Name from Runners WHERE Name LIKE 'T%'", myConnection)
' create a new dataset
Dim ds As DataSet = New DataSet
' fill dataset
da.Fill(ds, "Runners")
' write dataset contents to an xml file by calling WriteXml method
' Attach DataSet to DataGrid
'GridView1.DataSource = ds.Tables(0).DefaultView

End Sub
 
Sorry for late reply. This is the new code that works perfectly, well almost. The only problem I have left is when I do a search I cant search for anything else i.e. i'd have to close down and start again. Is there a way to close the connection and refresh when I search again?

Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("runnersdb.mdb")
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
' create a data adapter
'Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Runners", myConnection)
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Runners WHERE Name LIKE '%" & txtName.Text & "%'", myConnection)

' create a new dataset
Dim ds As DataSet = New DataSet
' fill dataset
'ds.Clear()
ds.Reset()

da.Fill(ds, "Runners")
' Attach DataSet to DataGrid

GridView1.DataSourceID() = ""
GridView1.DataSource = ds.Tables(0).DefaultView
'myConnection.Close()


End Sub

End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top