|
-
Feb 11th, 2005, 01:35 AM
#1
Thread Starter
Hyperactive Member
Will someone proofread this for me?
I am new to asp.net and want to start off on the right foot... Now the code works properly.. and it does add the data to the database which for all intentions is all I need... But being self taught I want to make sure I did this properly...
So will someone proof this for me and see if I am headed in the right direction? Basically I just want to make sure I am adding data using the correct technique!
Also I wanted to use a dropdown box for the state field but I kept getting and error saying I could not use .Text ... So I converted it to a Textfield for now... what do I use please?
Thanks!!
Code:
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<script runat="server">
Sub Button_Click( s as object, e as eventargs )
dim myConnection as SqlConnection
dim strInsert as string
dim cmdInsert as SqlCommand
myConnection = new sqlconnection( "server=localhost;uid=myid;pwd=mypassword;database=store" )
strInsert = "insert t_manufacturer (manufacturer_name, manufacturer_address1, manufacturer_address2, manufacturer_city, manufacturer_state, manufacturer_zip, manufacturer_country, manufacturer_account, manufacturer_url, manufacturer_primary_contact, manufacturer_primary_telephone, manufacturer_primary_telephone_ext, manufacturer_primary_email ) values ( @txtManufacturerName, @txtAddress1, @txtAddress2, @txtCity, @txtState, @txtZip, @txtCountry, @txtAccount, @txtManufacturerURL, @txtPrimaryContact, @txtPrimaryContactPhone, @txtPrimaryContactExt, @txtPrimaryContactEmail )"
cmdInsert = New SqlCommand( strInsert, myConnection )
cmdInsert.Parameters.Add("@txtManufacturerName", txtManufacturerName.Text )
cmdInsert.Parameters.Add("@txtAddress1", txtAddress1.Text )
cmdInsert.Parameters.Add("@txtAddress2", txtAddress2.Text )
cmdInsert.Parameters.Add("@txtCity", txtCity.Text )
cmdInsert.Parameters.Add("@txtState", txtState.Text )
cmdInsert.Parameters.Add("@txtZip", txtZip.Text )
cmdInsert.Parameters.Add("@txtCountry", txtCountry.Text )
cmdInsert.Parameters.Add("@txtAccount", txtAccount.Text )
cmdInsert.Parameters.Add("@txtManufacturerURL", txtManufacturerURL.Text )
cmdInsert.Parameters.Add("@txtPrimaryContact", txtPrimaryContact.Text )
cmdInsert.Parameters.Add("@txtPrimaryContactPhone", txtPrimaryContactPhone.Text )
cmdInsert.Parameters.Add("@txtPrimaryContactExt", txtPrimaryContactExt.Text )
cmdInsert.Parameters.Add("@txtPrimaryContactEmail", txtPrimaryContactEmail.Text )
myConnection.open()
cmdInsert.ExecuteNonQuery()
myConnection.Close()
lblStatus.Text = txtManufacturerName.Text + " has been added succesfully!"
End Sub
</script>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Create New Manufacturer</title>
</head>
<body>
<form runat="server">
<div align="center">
<center>
<table border="0" cellpadding="2" style="border-collapse: collapse" bordercolor="#111111" width="778" id="AutoNumber1" height="0">
<tr>
<td width="100%">
<table border="0" cellpadding="2" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2" height="0">
<tr>
<td width="100%"><b><font face="Verdana" size="2">Create New
Manufacturer:
<asp:Label ForeColor="#FF0000" ID="lblStatus" runat="server" />
</font></b></td>
</tr>
<tr>
<td width="100%"><font face="Verdana" size="1">Please complete the
following information to add a new manufacturer.</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%">
<table width="75%" border="0" cellpadding="2" bordercolor="#111111" id="AutoNumber3" style="border-collapse: collapse">
<tr>
<td width="30%"><b><font face="Verdana" size="1">Manufacturer Name:</font></b></td>
<td width="70%">
<asp:TextBox Columns="28" Font-Name="Verdana" Font-Size="8" ID="txtManufacturerName" MaxLength="80" runat="server" TextMode="SingleLine" ToolTip="Manufacturer's Name" TabIndex="1" />
<b><font face="Verdana" size="1" color="#FF0000"><span class="redhighlight_text">*</span></font></b></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">Address (1):</font></b></td>
<td width="71%">
<asp:TextBox ID="txtAddress1" ToolTip="Manufacturer's Address Line 1" TextMode="SingleLine" runat="server" Columns="28" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="2" />
<b><font face="Verdana" size="1" color="#FF0000"><span class="redhighlight_text">*</span></font></b></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">Address (2):</font></b></td>
<td width="71%">
<asp:TextBox ID="txtAddress2" ToolTip="Manufacturer's Address Line 2" TextMode="SingleLine" runat="server" Columns="28" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="3" /></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">City:</font></b></td>
<td width="71%">
<asp:TextBox ID="txtCity" ToolTip="Manufacturer's City" TextMode="SingleLine" runat="server" Columns="28" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="4" />
<b><font face="Verdana" size="1" color="#FF0000"><span class="redhighlight_text">*</span></font></b></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">State:</font></b></td>
<td width="71%">
<b><font face="Verdana" size="1" color="#FF0000"><span class="redhighlight_text">
<asp:TextBox ID="txtState" ToolTip="Manufacturer's City" TextMode="SingleLine" runat="server" Columns="28" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="5" />
*</span></font></b></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">Zip Code:</font></b></td>
<td width="71%"><font size="1">
<asp:TextBox ID="txtZip" ToolTip="Manufacturer's Zip Code" TextMode="SingleLine" runat="server" Columns="10" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="6" />
</font><b><font face="Verdana" size="1" color="#FF0000"><span class="redhighlight_text">*</span></font></b></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">Country:</font></b></td>
<td width="71%"> <b><font face="Verdana" size="1" color="#FF0000"><span class="redhighlight_text">
<asp:TextBox ID="txtCountry" ToolTip="Manufacturer's City" TextMode="SingleLine" runat="server" Columns="28" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="7" />
*</span></font></b></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">Account #:</font></b></td>
<td width="71%">
<asp:TextBox ID="txtAccount" ToolTip="Your Account # for Manufacturer" TextMode="SingleLine" runat="server" Columns="28" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="8" />
<b><font face="Verdana" size="1" color="#FF0000"><span class="redhighlight_text">*</span></font></b></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">Manufacturer URL:</font></b></td>
<td width="71%">
<asp:TextBox ID="txtManufacturerURL" ToolTip="Web Address of Manufacturer" TextMode="SingleLine" runat="server" Columns="28" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="9" /></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">Primary Contact:</font></b></td>
<td width="71%">
<asp:TextBox ID="txtPrimaryContact" ToolTip="Contact's Name" TextMode="SingleLine" runat="server" Columns="28" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="10" /></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">Primary Contact
Telephone:</font></b></td>
<td width="71%"><font size="1">
<asp:TextBox ID="txtPrimaryContactPhone" ToolTip="Contact's Telephone Number" TextMode="SingleLine" runat="server" Columns="14" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="11" />
</font><b><font face="Verdana" size="1" color="#FF0000"><span class="redhighlight_text">*</span></font></b><font size="1"><font face="Verdana">
Ext: </font>
<asp:TextBox ID="txtPrimaryContactExt" ToolTip="Contact's Telephone Number Extension" TextMode="SingleLine" runat="server" Columns="5" Font-Name="Verdana" Font-Size="8" MaxLength="5" TabIndex="12" />
</font></td>
</tr>
<tr>
<td width="29%"><b><font face="Verdana" size="1">Primary Contact
Email:</font></b></td>
<td width="71%">
<asp:TextBox ID="txtPrimaryContactEmail" ToolTip="Contact's Email" TextMode="SingleLine" runat="server" Columns="28" Font-Name="Verdana" Font-Size="8" MaxLength="80" TabIndex="13" /></td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button Font-Name="Verdana" Font-Names="Verdana" Font-Size="8" ID="btnSubmit" runat="server" OnClick = "Button_Click" Text="Add Manufacturer" ToolTip="Add Manufacturer" TabIndex="14" Width="110" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%"> </td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
Last edited by Anjari; Feb 11th, 2005 at 01:46 AM.
-
Feb 11th, 2005, 04:26 AM
#2
Re: Will someone proofread this for me?
Your method is fine.
For the dropdown, use SelectedValue or SelectedText properties of the dropdown.
-
Feb 11th, 2005, 06:27 AM
#3
Retired VBF Adm1nistrator
Re: Will someone proofread this for me?
Personal preference, I would put the code into your Code Behind file, but its actually totally irrelevant.
Another thing I would note. ExecuteNonQuery() returns an integer value with the number of rows affected by your SQL Command. You might want to check that value before assuming and updating lblStatus
.... though having said that, given that there is no Exception handling in that piece of code you'll know when the update doesn't complete.
Anyway, all looks good to me
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 11th, 2005, 09:39 AM
#4
Thread Starter
Hyperactive Member
Re: Will someone proofread this for me?
Oh I agree... This form is very basic... Can you point me in a tutorial direction that would show me how to check for duplicates, errors, etc?
Also one other thing I would like to do is create a "manufacturer_created_date" field... can someone tell me how I would grab the date and write it to the database? I figured I could probably assign a hidden field or label a date when the form was created but I would like the actual time to be written when the button is clicked... Im sure its something simple but it eludes me at this moment.
Thanks!
PS - I keep hearing about "Code Behind" but I am totally clueless can someone give me a small meaning or point me in the right direction on what this refers to?
-
Feb 11th, 2005, 09:44 AM
#5
Retired VBF Adm1nistrator
Re: Will someone proofread this for me?
Right click your web form in the Solution Explorer and select View Code
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 13th, 2005, 01:16 AM
#6
Thread Starter
Hyperactive Member
Re: Will someone proofread this for me?
Im using Macromedia Dreamweaver dont think I have that... anywho... I still need a way to capture the date information???
Anyone, anyone?
Anjari
-
Feb 14th, 2005, 07:39 PM
#7
Frenzied Member
Re: Will someone proofread this for me?
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|