I have been developing with ASP 3.0 and VB6 for the past few years and I decided it was finally time to learn .NET. I have recently purchased VB.NET and I am running on a win2k adv server box using Access 2002 as a back end (I am working on aquiring SQL Server). I am attempting to test my first code in ASP.NET but I am having difficulties. I am hoping somebody may be able to point me in the correct direction. The code I am using is posted below.
<HTML>
<HEAD>
<title>WebForm1</title>
<script language="vb" runat="server">
Sub Page_OnLoad(sender as Object, e as EventArgs)
Response.Write("called")
Dim strConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\inetpub\wwwroot\webapp1\db1.mdb;"Dim objConn as New OleDbConnection(strConnString)
Dim strSQL as String = "SELECT * FROM Names"
Dim objCmd as new OleDbCommand(strSQL, objConn)MyDataGrid.DataSource = objCmd.ExecuteReader
MyDataGrid.DataBind()
End SubSub MyButton_OnClick(Sender as Object, e as EventArgs)
Response.Write("called")
End Sub
</script>
</HEAD>
<body>
<form name="frmTest" runat="server">
<asp:Button ID="MyButton" Runat="server" Text="Click Me" />
<asp:DataGrid ID="MyDataGrid" Runat="server" BorderColor=#ff00ff />
</form>
</body>
</HTML>
For some reason when I view this .aspx page the datagrid doesn't show up and neither does the data access portion. Coming from an ASP 3.0 background my first instinct was to place the "response.write" command in the page_load sub to see if that sub was being called correctly. None of the above shows up on the page. However, if I place a plain text box or button it shows up fine. I have searched the forums here and found a few posts that had a similar problem, so I ran the aspnet_regiis -i from the cmd prompt and it installed correctly, but it didn't help my problems any. I also made sure that IIS has this set up as an application. Being new to .NET I am not sure where to go from here and would appreciate any feedback on how to fix this issue.
Regards,
Coreywell the first thin I see is that you are using Page_OnLoad which is incorrect, it is Page_Load. Also you have not opened the connection so just add this before you define your sql string
objConn.Open()
then after you you bind the data, make sure you close the connection using
objConn.Close()
That should solve the problem
Hi,
first off all: response.write was used a lot in classic asp but in asp.net it's nicer to use trace.write (or trace.warn). Make sure that tracing is enabled for the page.
You're probably using webmatrix as a tool so it's better to check out theguided tour first.
Grz, Kris.
Thanks for the replies. I began to experiment with the code behind files and finally figured out that my problem was with the name of my db table name. It was a reserved word and when I surrounded it by "[ ]" it began working properly.
Regards,
Corey
0 comments:
Post a Comment