Is it possible?

AznCutie

Member
Joined
Nov 13, 2002
Messages
16
Location
West coast
Is it possible to bind data to an HTML table cell? If so, whats the syntax...?

For example - I want to show a specific persons record on a page. The source is an mdb file. Theres two ways I can think of to do this, and one of them is using a datagrid, however that doesnt produce the desired results... If theres some way of showing a specific item in a cell, then Id rather do that... Thanks in advance!
 
Originally posted by Robby
I dont think you can bind to an HTML table.
SOrry I didnt get it, what do you want to do?
Basically pull up a user or employees record, showing their email address, mailing address, etc... Information thats stored in a database, and shown in a table.

Basically, like this.
 
The link errors out, the msg is...

Line 39: objCN.Close()
Line 40: lblEmployeeID.Text = _
Line 41: objDS.Tables("EmployeeData").Rows(0)!EmployeeID

It looks like a Dataset is feeding a Label, the rest of it may be a DataGrid or DataList (as wyrd said).
 
Okay... I got that... For some reason, its still bugging out though. Can anyone help me out?

Code:
Sub Page_Load(Sender As Object, E As EventArgs)
			Dim objCN  as OleDbConnection	 Database Connection object
			Dim objDA  as OleDbDataAdapter   Database Adaptor object
	                Dim objDS  as DataSet            Dataset object
			Dim objCM  as OleDbCommand
			Dim strSQL as String
			Dim strCN  as String
		   
			If Not IsPostBack Then
				   strCN = "PROVIDER = Microsoft.Jet.OLEDB.4.0;" & "DATA SOURCE=" & Server.MapPath("emps.mdb;" ) 		   
   					    
				objCN = New OleDbConnection( strCN )	
				objCN.Open()
			
				strSQL = " SELECT EmployeeID, LastName, FirstName FROM Employees WHERE EmployeeID = @EmployeeID"
				objDA = New OleDBDataAdapter( strSQL, objCN )
				objDA.SelectCommand.Parameters.Add("@EmployeeID")
				objDS = New DataSet
				objDA.Fill(objDS, "Employees")
				objCN.Close()
				lblEmployeeID.text = objDS.Tables("EmployeeData").Rows(0)!EmployeeID
				lblName.text = objDS.Tables("EmployeeData").Rows(0)!LastName
				lblDepartment.text = objDS.Tables("EmployeeData").Rows(0)!DepartmentID
				lblEmail.text = objDS.Tables("EmployeeData").Rows(0)!EmailAddress
				lblNumber.text = objDS.Tables("EmployeeData").Rows(0)!PhoneNumber
				lblNotes.text = objDS.Tables("EmployeeData").Rows(0)!Notes
			end if
		end sub
 
Its hard to tell without you posting the error messages, but a few things..

Change your page load to..
Code:
Sub Page_Load()

And also your connection string seems a little funky, perhaps change it to..
Code:
strCN = "PROVIDER = Microsoft.Jet.OLEDB.4.0; DATA SOURCE=" & Server.MapPath("emps.mdb")

And your parameter is wrong I believe. Youre using the set up for SQL Server classes, but youre using OleDB. Change your sql select to;
Code:
strSQL = " SELECT EmployeeID, LastName, FirstName FROM Employees WHERE EmployeeID = ?"

And also your parameter itself seems wrong. It should be ("@paramter", source) and all you have is parameter. Perhaps change it to something like;
Code:
objDA.SelectCommand.Parameters.Add("@EmployeeID", txtEmployeeID.Text)

As a last thing, you can bind data to ANY web control (as far as I know). I noticed that youre using labels, and you can bind data to your labels. Id suggest searching for info in the MSDN library.

Anyway, hope that helps.. I have a limited knowledge of ASP.NET stuff, but hopefully I at least set you in the right direction. If you need more help post the code, the error message, and what line the error(s) are on.
 
Back
Top