 |
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
|
|
|

October 21st, 2003, 09:19 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Creating Tables Programmatically
Any good tutorials on how to create tables programmatically?
|
The Following User Says Thank You to stu9820 For This Useful Post:
|
|

October 21st, 2003, 11:19 AM
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What is your database back end?
Sal
|

October 21st, 2003, 12:02 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
It can be either MSDE or Access. I am familiar with both.
|

October 21st, 2003, 01:27 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
'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
|

October 21st, 2003, 01:45 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|

October 21st, 2003, 01:53 PM
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

October 22nd, 2003, 07:38 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
katsarosj, your first response is what I'm looking for.
Thanks.
|

October 22nd, 2003, 08:46 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|

October 22nd, 2003, 01:41 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

October 22nd, 2003, 02:18 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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?
|
|
 |