3 Replies - 3732 Views - Last Post: 17 April 2008 - 07:49 AM Rate Topic: -----

#1 yog_rock2000  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 26-September 06

Can't insert insert VALUES of asp.net to the database

Post icon  Posted 10 April 2008 - 11:32 AM

Hello there, I have been trying to insert VALUES of registration page in asp.net to my database in MS-ACCESS. But, the problem is that there is nothing been added in databse once I click submit button. Can please tell me were I am goin wrong. Below I have provide the code.

Filename: - Registration.aspx.vb

Partial Class Registration
	Inherits System.Web.UI.Page


	Dim conn As System.Data.OleDb.OleDbConnection
	Dim cmd As System.Data.OleDb.OleDbCommand
	Dim dr As System.Data.OleDb.OleDbDataReader


	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Register.Load
		Try
			conn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Nuke\Desktop\www.carwale.com\www.carwale.com\carwale.mdb")

			cmd = New System.Data.OleDb.OleDbCommand("SELECT * IndividualDetails", conn)

			conn.Open()

			dr = cmd.ExecuteReader
			dr.Read()



		Catch ex As Exception

		End Try
	End Sub
	Protected Sub Register_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Register.Click


		cmd.CommandType = Data.CommandType.Text

		cmd.CommandText = "insert into IndividualDetails (Name,Email,Password,Code,MobileNumber,LandlineNumber) values('" & Name.Text & "', '" & Email.Text & "', '" & Password.Text & "', '" & Code.Text & "', '" & Mnumber.Text & "', '" & Pnumber.Text & "')"


		conn.Close()

		Response.Redirect("Default.aspx")
	End Sub

End Class




Filename: - Registration.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Registration.aspx.vb" Inherits="Registration" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

		End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
		<table style="width: 100%; position: absolute; height: 100%; left: 10px; top: 65px;">
			<tr>
				<td colspan="3" style="height: 10px">
					<asp:Label ID="Label2" runat="server" Text="* marked fields are compulsory " Width="200px"></asp:Label></td>
			</tr>
			<tr>
				<td colspan="3">
					<asp:Label ID="Label3" runat="server" Text="Contact Information" Width="149px"></asp:Label></td>
			</tr>
			<tr>
				<td style="width: 249px; height: 6px">
					<asp:Label ID="Label4" runat="server" Text="Your Name *" Width="106px"></asp:Label></td>
				<td style="height: 6px; width: 500px;" colspan="2">
					<asp:TextBox ID="Name" runat="server"></asp:TextBox>
					<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter your Name" ControlToValidate="Name"></asp:RequiredFieldValidator></td>
			</tr>
			<tr>
				<td style="width: 249px; height: 61px">
					<asp:Label ID="Label5" runat="server" Text="Your Email *"></asp:Label></td>
				<td style="height: 61px; width: 500px;" colspan="2">
					<asp:TextBox ID="Email" runat="server" Width="206px"></asp:TextBox>
					<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Not a valid Email"
						ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="Email"></asp:RegularExpressionValidator><br />
					<asp:Label ID="Label6" runat="server" Text="eg. arunsahlam@yahoo.com" Width="172px"></asp:Label>&nbsp;</td>
			</tr>
			<tr>
				<td style="width: 249px; height: 21px">
					<asp:Label ID="Label7" runat="server" Text="Confirm Email *"></asp:Label></td>
				<td style="height: 21px; width: 500px;" colspan="2">
					<asp:TextBox ID="CEmail" runat="server" Width="208px"></asp:TextBox>
					<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="Email"
						ControlToValidate="CEmail" ErrorMessage="Email ID don't match"></asp:CompareValidator></td>
			</tr>
			<tr>
				<td style="width: 249px; height: 21px">
					<asp:Label ID="Label8" runat="server" Text="Set Password *"></asp:Label></td>
				<td style="height: 21px; width: 500px;" colspan="2">
					<asp:TextBox ID="Password" runat="server" MaxLength="10" TextMode="Password"></asp:TextBox>&nbsp;
					<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Password"
						ErrorMessage="Please enter your password"></asp:RequiredFieldValidator></td>
			</tr>
			<tr>
				<td style="width: 249px; height: 21px">
					<asp:Label ID="Label9" runat="server" Text="Confirm Password *"></asp:Label></td>
				<td style="height: 21px; width: 500px;" colspan="2">
					<asp:TextBox ID="CPassword" runat="server" MaxLength="10" TextMode="Password"></asp:TextBox>
					<asp:CompareValidator ID="CompareValidator2" runat="server" ControlToCompare="Password"
						ControlToValidate="CPassword" ErrorMessage="Password don't match"></asp:CompareValidator></td>
			</tr>
			<tr>
				<td colspan="3" style="height: 13px">
					<asp:Label ID="Label10" runat="server" Text="Phone Numbers *[At least provide one phone number] "
						Width="335px"></asp:Label></td>
			</tr>
			<tr>
				<td style="width: 249px; height: 1px">
					<asp:Label ID="Label11" runat="server" Text="Landline No." Width="111px"></asp:Label></td>
				<td align="left" colspan="2" style="height: 1px; width: 500px;" valign="middle">
					<asp:TextBox ID="Code" runat="server" Width="33px" MaxLength="3"></asp:TextBox>
					-
					<asp:TextBox ID="Pnumber" runat="server"
							Width="103px" MaxLength="8"></asp:TextBox>
					&nbsp;&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
						ErrorMessage="Must be in form: XXX - XXXXXXX" ControlToValidate="Pnumber"></asp:RequiredFieldValidator>
				</td>
			</tr>
			<tr>
				<td style="width: 249px; height: 1px">
				</td>
				<td align="left" colspan="2" valign="middle" style="width: 500px">
				   <asp:Label ID="Label12" runat="server" Text="[Code]" Width="41px"></asp:Label>&nbsp;
					<asp:Label ID="Label13" runat="server" Text="-  [Number]" Width="114px"></asp:Label>&nbsp;
				</td>
			</tr>
			<tr>
				<td style="width: 249px">
					<asp:Label ID="Label14" runat="server" Text="Mobile No." Width="90px"></asp:Label>
					&nbsp; &nbsp;<asp:Label ID="Label15" runat="server" Text="+91 -"></asp:Label>
					&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
					&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</td>
				<td style="height: 21px; width: 500px;" colspan="2">
					<asp:TextBox ID="Mnumber" runat="server" MaxLength="10"></asp:TextBox>
					<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Must be in form: XXXXXXXXX" ControlToValidate="Pnumber"></asp:RequiredFieldValidator></td>
			</tr>
			<tr>
				<td style="width: 249px; height: 21px">
					<asp:Label ID="Label16" runat="server" Text="Where did you hear about CarWale.com ? *"></asp:Label></td>
				<td style="height: 21px; width: 500px;" colspan="2">
					<asp:DropDownList ID="Hearing" runat="server">
						<asp:ListItem>Select</asp:ListItem>
						<asp:ListItem>Friend</asp:ListItem>
						<asp:ListItem>Newspaper</asp:ListItem>
						<asp:ListItem>Magazine</asp:ListItem>
						<asp:ListItem>SMS</asp:ListItem>
						<asp:ListItem>Email</asp:ListItem>
						<asp:ListItem>Google Search</asp:ListItem>
						<asp:ListItem>Yahoo Search</asp:ListItem>
						<asp:ListItem>MSN Search</asp:ListItem>
						<asp:ListItem>Rediff</asp:ListItem>
						<asp:ListItem>Other Search</asp:ListItem>
						<asp:ListItem>Pamphlet</asp:ListItem>
						<asp:ListItem>Bus</asp:ListItem>
						<asp:ListItem>Other</asp:ListItem>
					</asp:DropDownList></td>
			</tr>
			<tr>
				<td colspan="3" style="height: 21px">
					<asp:CheckBox ID="CheckBox1" runat="server" Text="I agree to accept your User Agreement and Privacy Policy electronically, and further acknowledge that I have read and agree to the User Agreement and Privacy Policy "
						Width="531px" /></td>
			</tr>
			<tr>
				<td colspan="3" style="height: 21px">
					<asp:Button ID="Register" runat="server" Text="Register Me" Width="146px" />
					<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/carwale.mdb" InsertCommand="INSERT INTO IndividualDetails( Name, Email, [Password], Code, MobileNumber, LandlineNumber) VALUES ( '&quot;  &quot;', '&quot; &quot;', '&quot;  &quot;', '&quot;  &quot;', '&quot; &quot;', '&quot; &quot;')" SelectCommand="SELECT  [MobileNumber], [LandlineNumber], [Name], [Email], [Password], [Code] FROM [IndividualDetails]"></asp:AccessDataSource>
				</td>
			</tr>
		</table>
		<asp:Label ID="Label1" runat="server" Text="New Member : Please Register Here" Width="234px"></asp:Label><br />
		<hr style="width: 746px" />
		<br />
	</form>
</body>
</html>



Waiting for ur replies... :^:

Is This A Good Question/Topic? 0
  • +

Replies To: Can't insert insert VALUES of asp.net to the database

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Can't insert insert VALUES of asp.net to the database

Posted 10 April 2008 - 05:39 PM

Are you sure you don't need to execute your command after you've prepared it? That would be my first guess.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Can't insert insert VALUES of asp.net to the database

Posted 10 April 2008 - 05:52 PM

He is correct, you need to execute your query in order for it to go into the database. You cannot add data via osmosis :) Since you're not returning any values, just inserting them, you should use the ExecuteNonQuery Method


Protected Sub Register_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Register.Click
       'Create our OleDbConnection Object
       Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Nuke\Desktop\www.carwale.com\www.carwale.com\carwale.mdb")
       'Create a new OleDbCommand Object
       Dim cmd As New OleDbCommand()

        'Set properties of our OleDbCommand Object
        With cmd
              .CommandType = Data.CommandType.Text
              .CommandText = "insert into IndividualDetails (Name,Email,Password,Code,MobileNumber,LandlineNumber) values('" & Name.Text & "', '" & Email.Text & "', '" & Password.Text & "', '" & Code.Text & "', '" & Mnumber.Text & "', '" & Pnumber.Text & "')"
              .Connection = conn
        End With
        
        'Open our connection
        conn.Open()

        'Execute our query
        cmd.ExecuteNonQuery()

        'Close our connection
        conn.Close()

        Response.Redirect("Default.aspx")
End Sub


Was This Post Helpful? 0
  • +
  • -

#4 yog_rock2000  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 26-September 06

Re: Can't insert insert VALUES of asp.net to the database

Posted 17 April 2008 - 07:49 AM

Thank you very much for ur help...
Was This Post Helpful? 1

Page 1 of 1