Hi,
Just want to make sure about some stuff before I start my website over.
Why? Because I was new to web development, and no EVERYTHING happen on the server side (asp.net) and my web application is slow, crash, etc, etc.
This is what I "realised" I should do:
1) Create my page layout in HTML.
2) Everything that don't need to happen on the server side, should be implemneted using Javascript
3) Everything else (like database talks, etc) can occur in the code behind.
4) Language specific information, like text, image names, stylesheet names (different images/stylesheets are used for different langauges)
this the right "attitude"?
make me think...asp.net ain't that "new way" of doing things...you should use it as extension to classic asp, because html + javascript = asp...right?
darn!, I miss deskop development! :sick:No!
ASP is also server side, but it was more inline than ASP.NET is. ASP is still server side, and so is ASP.NET.
The attitude you're looking for is:
ASP.NET is something you'd use in conjunction with HTML, JavaScript and CSS to make a complete web application.
I think most of the work should be done with JavaScript, if its not necessary to post the form.
Showing posts with label stuff. Show all posts
Showing posts with label stuff. Show all posts
Wednesday, March 21, 2012
Friday, March 16, 2012
Please Help Me, I Am to Be Fired!
What I ask can be very familiar to most of you.
So, please don't point me a URL in MSDN,
I can't understand the stuff there. Instead please add
the "lacking" codes and help me to complete the code.
I need to store First Name and Last Name of users
which come as user inputs through text boxes in
a web form to an existing data table as a new data row.
I used DataSets. I heard it is bulky. Is there any other
way of achieving it? I have included the database
connection in a method that is called for the click
event of the submit button. Instead, Should I include
it in the Page load event?
I also want to know weather there is a way to give
relative paths for database connection instead of
an absolute one which won't be practical when
I move the stuff to a web server.
Below I have included the complete code even with
HTML. The error I get is "Update requires a valid
InsertCommand when passed DataRow collection
with new rows"
It occurs due to the statement,
objCmd.Update(ds, "contacts")
Please help me to complete the code. I am a
trainee and this is a practice project that
I should submit. I couldn't complete it for
2 weeks. I made forum posts and got MSDN
links. Please don't do that. Just tell me what code
to where I should add. I really appreciate your
help. Here is the code,
<%@dotnet.itags.org. Page Language="VB" Debug="true" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %>
<script runat="server">
sub Add(obj as object, e as EventArgs)
dim objConn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\users\database\users.mdb")
objConn.Open()
dim objCmd as new OleDbDataAdapter("select * from contacts", objConn)
dim ds as DataSet = new DataSet()
objCmd.Fill(ds, "contacts")
dim dr as DataRow = ds.Tables("contacts").NewRow()
dr(1)=txtFirstName.text
dr(2)=txtLastName.Text
ds.Tables("contacts").Rows.Add(dr)
objCmd.Update(ds, "contacts")
objConn.Close()
end sub
</script>
<html>
<body>
<form runat="server">
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="40%" align="right"><strong>First Name</strong></td>
<td width="60%">
<asp:textbox ID="txtFirstName" runat="server" />
</td>
</tr>
<tr>
<td align="right"><strong>Last Name</strong></td>
<td>
<asp:textbox ID="txtLastName" runat="server" />
</td>
</tr>
<tr align="center">
<td colspan="2">
<asp:button ID="btnAdd" runat="server" OnClick="Add" Text="Add" />
</td>
</tr>
</table>
</form>
</body>
</html>You could use a datareader instead of a dataadapter, it's slightly more code but a lot faster.
You can use server.mappath("/my.mdb") to connect to a relative path.
It's all in the error "Update requires a valid InsertCommand when passed DataRow collection with new rows". You've only given the dataadapter a select command so it doesn't know how to insert,update or delete.
After
dim objCmd as new OleDbDataAdapter("select * from contacts", objConn)
add
Dim cb as New OleDbCommandBuilder(objCmd)
These concepts are really simple and to be harshly honest, if you can't understand it, perhaps programming isn't really for you. Then again if you're going to get fired as you say, you shouldn't care. :D
So, please don't point me a URL in MSDN,
I can't understand the stuff there. Instead please add
the "lacking" codes and help me to complete the code.
I need to store First Name and Last Name of users
which come as user inputs through text boxes in
a web form to an existing data table as a new data row.
I used DataSets. I heard it is bulky. Is there any other
way of achieving it? I have included the database
connection in a method that is called for the click
event of the submit button. Instead, Should I include
it in the Page load event?
I also want to know weather there is a way to give
relative paths for database connection instead of
an absolute one which won't be practical when
I move the stuff to a web server.
Below I have included the complete code even with
HTML. The error I get is "Update requires a valid
InsertCommand when passed DataRow collection
with new rows"
It occurs due to the statement,
objCmd.Update(ds, "contacts")
Please help me to complete the code. I am a
trainee and this is a practice project that
I should submit. I couldn't complete it for
2 weeks. I made forum posts and got MSDN
links. Please don't do that. Just tell me what code
to where I should add. I really appreciate your
help. Here is the code,
<%@dotnet.itags.org. Page Language="VB" Debug="true" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %>
<script runat="server">
sub Add(obj as object, e as EventArgs)
dim objConn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\users\database\users.mdb")
objConn.Open()
dim objCmd as new OleDbDataAdapter("select * from contacts", objConn)
dim ds as DataSet = new DataSet()
objCmd.Fill(ds, "contacts")
dim dr as DataRow = ds.Tables("contacts").NewRow()
dr(1)=txtFirstName.text
dr(2)=txtLastName.Text
ds.Tables("contacts").Rows.Add(dr)
objCmd.Update(ds, "contacts")
objConn.Close()
end sub
</script>
<html>
<body>
<form runat="server">
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="40%" align="right"><strong>First Name</strong></td>
<td width="60%">
<asp:textbox ID="txtFirstName" runat="server" />
</td>
</tr>
<tr>
<td align="right"><strong>Last Name</strong></td>
<td>
<asp:textbox ID="txtLastName" runat="server" />
</td>
</tr>
<tr align="center">
<td colspan="2">
<asp:button ID="btnAdd" runat="server" OnClick="Add" Text="Add" />
</td>
</tr>
</table>
</form>
</body>
</html>You could use a datareader instead of a dataadapter, it's slightly more code but a lot faster.
You can use server.mappath("/my.mdb") to connect to a relative path.
It's all in the error "Update requires a valid InsertCommand when passed DataRow collection with new rows". You've only given the dataadapter a select command so it doesn't know how to insert,update or delete.
After
dim objCmd as new OleDbDataAdapter("select * from contacts", objConn)
add
Dim cb as New OleDbCommandBuilder(objCmd)
These concepts are really simple and to be harshly honest, if you can't understand it, perhaps programming isn't really for you. Then again if you're going to get fired as you say, you shouldn't care. :D
Subscribe to:
Posts (Atom)