Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Help with data access page in ASP.NET


  • Please log in to reply

#1
JAW1971

JAW1971

    New Member

  • Member
  • Pip
  • 9 posts
Hi All- Not sure if I can post this- but I am going to give it a shot. I am taking an elective (My FINAL ONE) for my online college...I choose ASP.NET as my elective because I thought it would be interesting to learn more of it. I know a 'tiny bit' already. I was NOT Prepared for taking it online- I have no support from other classmates or the 'so called instructor' it is sort of a 'do it on your own class'

I am having some issues and I do not know how to Trouble shoot my problem any further.
I have a page that accesses data based on the selected drop down from the Access Northwind Database.
The data is not coming back and i am not sure why.

This is what I have for my code and I am using the WebMatrix software...
If anyone can provide any assistance I would appreciate it..


<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

	Sub Page_load(Sender As Object, Byval E As EventArgs)
			If Not Page.IsPostBack Then
			Dropdownlist1.DataTextField = "CompanyName"
			Dropdownlist1.dataValueField= "ShipperID"
			DropDownList1.DataSource = GetShippers()
			DropDownList1.DataBind()
			   Label2.text=DropDownList1.selecteditem.value
			End If
			End Sub
	
	Sub getlabel(byval sender As Object, ByVal e As EventArgs)
	Label2.text=DropDownList1.selecteditem.value
	End Sub
	
	SUB BUTTON1_click(byval sender As Object, ByVal e As EventArgs)
	Call GETORDER()
	datagrid1.visible=true
	End Sub
	
		  Function GetShippers() As System.Data.DataSet
					Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\WEB_STUFF\AS"& _
			"P\Northwind.mdb"
					Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
					Dim queryString As String = "SELECT [Shippers].[ShipperID],[Shippers].[Companyname] FROM [Shippers]"
					Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
					dbCommand.CommandText = queryString
					dbCommand.Connection = dbConnection
					Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
					dataAdapter.SelectCommand = dbCommand
					Dim dataSet As System.Data.DataSet = New System.Data.DataSet
					dataAdapter.Fill(dataSet)
				   Return dataSet
				End Function
	
	FUNCTION GETORDER()
				   Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\WEB_STUFF\AS"& _
			 "P\Northwind.mdb"
					 Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
	
					   dim ShipVia = dropdownlist1.selecteditem.value
					 Dim queryString As String = "SELECT [Orders].[OrderDate], [Orders].[ShipAddress] FROM [Orders] WHERE ([Orders]"& _
			 ".[ShipVia] = " & ShipVia & ")"
					 Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
					 dbCommand.CommandText = queryString
					 dbCommand.Connection = dbConnection
					 Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
						dataAdapter.SelectCommand = dbCommand
						Dim DSet As System.Data.DataSet = New System.Data.DataSet
					 dataAdapter.Fill(DSet)
						DataGrid1.DataSource = dset
						DataGrid1.DataBind()
					 return dset
					 End function

</script>
<html>
<head>
</head>
<body>
	<form runat="server">
		<asp:DropDownList id="DropDownList1" style="Z-INDEX: 100; LEFT: 16px; POSITION: absolute; TOP: 52px" runat="server" Autopostback="true" Datatextfield="CompanyName" Datavaluefield="Shipperid" OnSelectedIndexChanged="getlabel"></asp:DropDownList>
		<asp:Label id="Label2" style="Z-INDEX: 101; LEFT: 160px; POSITION: absolute; TOP: 50px" runat="server">Label</asp:Label><asp:Label id="Label3" style="Z-INDEX: 104; LEFT: 160px; POSITION: absolute; TOP: 11px" runat="server" font-bold="True">Shippers
		ID</asp:Label>
		<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 57px; POSITION: absolute; TOP: 103px" runat="server" AutoGenerateColumns="true"></asp:DataGrid>
		<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 245px; POSITION: absolute; TOP: 44px" runat="server" Text="Button"></asp:Button>
		<!-- Insert content here -->
	</form>
</body>
</html>

  • 0

Advertisements


#2
JAW1971

JAW1971

    New Member

  • Topic Starter
  • Member
  • Pip
  • 9 posts
When I press the button- I am not seeing any data come back to my data grid. I am not sure what is wrong in the coding- because the label brings back the shipper id that is associated with the company- so that part I know works.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP