Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 21st, 2003, 09:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default Creating Tables Programmatically

Any good tutorials on how to create tables programmatically?

The Following User Says Thank You to stu9820 For This Useful Post:
  #2 (permalink)  
Old October 21st, 2003, 11:19 AM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What is your database back end?

Sal
  #3 (permalink)  
Old October 21st, 2003, 12:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

It can be either MSDE or Access. I am familiar with both.

  #4 (permalink)  
Old October 21st, 2003, 01:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

'Make sure you import namespace...
Imports System.Web.UI.WebControls
'If you don't you will have to add "System.Web.UI.WebControls" to the beginning of each (table, tablerow, tablecell)

'**********************
Dim tblTable as Table
Dim tblRow as TableRow
Dim tblCell as TableCell

tblTable = New Table
tblRow = New TableRow
tblCell = New TableCell

tblCell.Text = "This text would appear in the first column."
tblRow.Cells.Add(tblCell)

tblCell = New TableCell
tblCell.Text = "This text would appear in the second column."
tblRow.Cells.Add(tblCell)

tblTable.Rows.Add(tblRow)

frmFormName.Controls.Add(tblTable)

'**********************
Hope this helps.

J
  #5 (permalink)  
Old October 21st, 2003, 01:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Sorry,

Maybe I misunderstood...

If you want to create database tables in Access, try something like:

CREATE TABLE tblname
([Column1 Name] datatype, Column2Name datatype, Column3Name datatype);

To add a primary key:

CREATE TABLE TABLENAME
([Column1 Name] integer CONSTRAINT colIdx PRIMARY KEY, Column2Name text(25), Column3Name text(100));
INSERT INTO TABLENAME VALUES(integer_value, text_value, text_value);

I think this is correct, but been a while since I created Access tables in code.

Hope this helps and is what you are looking for.

J
  #6 (permalink)  
Old October 21st, 2003, 01:53 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

for MSDE look up Books on line and do it Through a command object in ADO,

for access you can also use ADOX, to find more info open Access help and go to
Microsoft Access Help
Microsoft ActiveX Data Objects
Microsoft ActiveX Data Objects
Microsoft ADOX Programmer's Reference
ADOX API Reference

This has detailed info on this. To use it you have to r eference the ADOX library.

Sal
  #7 (permalink)  
Old October 22nd, 2003, 07:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

katsarosj, your first response is what I'm looking for.

Thanks.


  #8 (permalink)  
Old October 22nd, 2003, 08:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Is it faster to build a table like this:
**********************
Dim tblTable as Table
Dim tblRow as TableRow
Dim tblCell as TableCell

tblTable = New Table
tblRow = New TableRow
tblCell = New TableCell

tblCell.Text = "This text would appear in the first column."
tblRow.Cells.Add(tblCell)

tblCell = New TableCell
tblCell.Text = "This text would appear in the second column."
tblRow.Cells.Add(tblCell)

tblTable.Rows.Add(tblRow)

frmFormName.Controls.Add(tblTable)
**************************


as opposed to this:
*****************
Dim strResultsHolder As String
strResultsHolder = "<table width=80% border=0 cellpadding=2 cellspacing=0>"
strResultsHolder &= "<tr><th colspan=3>" & myNews & "</th></tr>"

Dim r1 As DataRow
For Each r1 In objDataSet.Tables("dtNews").Rows
strResultsHolder &= "<tr><td width=140>" & r1("the_news") & "</td> <td>" & r1("short_sum") & "</td>"
If r1("news_link") = "No Link" Then
        strResultsHolder &= "<td width=90>No Link</td></tr>"
Else
        strResultsHolder &= "<td width=90><a href=" & r1("news_link") & " target=_blank>Get the story</a></td></tr>"
End If
Next

strResultsHolder &= "</table>"
display.InnerHtml = strResultsHolder
  #9 (permalink)  
Old October 22nd, 2003, 01:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

It is really up to you and what you are more comfortable with. I think the speed difference will be negligible. If you are using a code-behind file, then it gets compiled anyway which will speed it up.

The advantage to doing it the first way is that you can access the table/rows/columns methods and properties programmatically. Otherwise, I would just add the code as HTML(the portions where your are writing the table as strings) to the .aspx page (not the code behind) because it is less for the server to process.

Remember also that one of the great things about .net is the ability to "act" more like a windows form than classic asp.

So, if you want to create them programmatically, I would use the way that I presented to you. Hope this helps.

J

Quote:
quote:Originally posted by stu9820
 Is it faster to build a table like this:
**********************
Dim tblTable as Table
Dim tblRow as TableRow
Dim tblCell as TableCell

tblTable = New Table
tblRow = New TableRow
tblCell = New TableCell

tblCell.Text = "This text would appear in the first column."
tblRow.Cells.Add(tblCell)

tblCell = New TableCell
tblCell.Text = "This text would appear in the second column."
tblRow.Cells.Add(tblCell)

tblTable.Rows.Add(tblRow)

frmFormName.Controls.Add(tblTable)
**************************


as opposed to this:
*****************
Dim strResultsHolder As String
strResultsHolder = "<table width=80% border=0 cellpadding=2 cellspacing=0>"
strResultsHolder &= "<tr><th colspan=3>" & myNews & "</th></tr>"

Dim r1 As DataRow
For Each r1 In objDataSet.Tables("dtNews").Rows
strResultsHolder &= "<tr><td width=140>" & r1("the_news") & "</td> <td>" & r1("short_sum") & "</td>"
If r1("news_link") = "No Link" Then
        strResultsHolder &= "<td width=90>No Link</td></tr>"
Else
        strResultsHolder &= "<td width=90><a href=" & r1("news_link") & " target=_blank>Get the story</a></td></tr>"
End If
Next

strResultsHolder &= "</table>"
display.InnerHtml = strResultsHolder

  #10 (permalink)  
Old October 22nd, 2003, 02:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Once I have this:

objCell = New HtmlTableCell()
objCell.InnerHtml = "Time"
objCell.BgColor = "#C0C0C0"
objCell.Align = "center"
objRow.Cells.Add(objCell)

is there any way to have the row highlight when you move your mouse over it?





Similar Threads
Thread Thread Starter Forum Replies Last Post
creating multiple instances programmatically dcher BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 4 December 28th, 2007 02:21 PM
creating code programmatically mumphis Excel VBA 0 September 2nd, 2005 09:29 AM
Report - programmatically creating penta Access 12 May 19th, 2005 04:53 PM
Creating a table programmatically Bob Burns ASP.NET 1.0 and 1.1 Basics 2 July 15th, 2004 11:44 AM
Creating report programmatically liliarum BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 July 6th, 2004 09:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.