| | |
SQL database stores data twice
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 0
hi there,
i am coming up with a form. i have to insert data into the sql database. i am able to do that. The problem is that, when i insert, the data i entered one shows twice in the table. i just click once and there are the same data showing twice. I encountered this after including the dropdownlist. please help me. i am short of time.
i am coming up with a form. i have to insert data into the sql database. i am able to do that. The problem is that, when i insert, the data i entered one shows twice in the table. i just click once and there are the same data showing twice. I encountered this after including the dropdownlist. please help me. i am short of time.
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 0
This is my code in visual studio form. i used a sql insert statement, as below:
ALTER Procedure [dbo].[Insert_StaffRegis_Table]
@StaffID varchar(50),
@FirstName varchar(50),
@LastName varchar(50),
@Password varchar(50),
@RetypePass varchar(50),
@Designation char(1),
@Gender varchar(50),
@DOB varchar(50),
@Department varchar(50),
@SecretQues varchar(50),
@SecretAns varchar(50)
As
Insert into StaffRegis_Table (StaffID,FirstName,LastName,Password,RetypePass,Designation,Gender,DOB,Department,SecretQues,SecretAns)
values (@StaffID,@FirstName,@LastName,@Password,@RetypePass,@Designation,@Gender,@DOB,@Department,@SecretQues,@SecretAns)
Return
ALTER Procedure [dbo].[Insert_StaffRegis_Table]
@StaffID varchar(50),
@FirstName varchar(50),
@LastName varchar(50),
@Password varchar(50),
@RetypePass varchar(50),
@Designation char(1),
@Gender varchar(50),
@DOB varchar(50),
@Department varchar(50),
@SecretQues varchar(50),
@SecretAns varchar(50)
As
Insert into StaffRegis_Table (StaffID,FirstName,LastName,Password,RetypePass,Designation,Gender,DOB,Department,SecretQues,SecretAns)
values (@StaffID,@FirstName,@LastName,@Password,@RetypePass,@Designation,@Gender,@DOB,@Department,@SecretQues,@SecretAns)
Return
•
•
•
•
<script runat="server">
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SqlDataSource1.Insert()
End Sub
Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Inserting
e.Command.Parameters("@StaffID").Value = TextBox1.Text
e.Command.Parameters("@FirstName").Value = TextBox2.Text
e.Command.Parameters("@LastName").Value = TextBox3.Text
e.Command.Parameters("@Password").Value = TextBox4.Text
e.Command.Parameters("@RetypePass").Value = TextBox5.Text
e.Command.Parameters("@Designation").Value = DropDownList3.SelectedValue
e.Command.Parameters("@Gender").Value = DropDownList2.SelectedValue
e.Command.Parameters("@DOB").Value = TextBox8.Text
e.Command.Parameters("@Department").Value = TextBox9.Text
e.Command.Parameters("@SecretQues").Value = DropDownList1.SelectedValue
e.Command.Parameters("@SecretAns").Value = TextBox10.Text
End Sub
Protected Sub DropDownList3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style1
{
height: 40px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table border="0" cellpadding="0">
<tr>
<th>
<asp:Label ID="Label1" runat="server" Text="ID"></asp:Label></th>
<td align="left">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th>
<asp:Label ID="Label2" runat="server" Text="First Name"></asp:Label></th>
<td align="left">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox2">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th>
<asp:Label ID="Label3" runat="server" Text="Last Name"></asp:Label></th>
<td align="left">
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox3">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th>
<asp:Label ID="Label4" runat="server" Text="Password"></asp:Label></th>
<td align="left">
<asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="CompareValidator" ControlToValidate="TextBox5" ControlToCompare="TextBox4">*</asp:CompareValidator>
</td>
</tr>
<tr>
<th>
<asp:Label ID="Label5" runat="server" Text="Retype Password"></asp:Label></th>
<td align="left">
<asp:TextBox ID="TextBox5" runat="server" TextMode="Password"></asp:TextBox>
<asp:Label ID="Label11" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<th>
<asp:Label ID="Label6" runat="server" Text="Designation"></asp:Label></th>
<td align="left">
<aspropDownList ID="DropDownList3" runat="server" Width="150px"
onselectedindexchanged="DropDownList3_SelectedIndexChanged" >
<asp:ListItem Value="M">Manager</asp:ListItem>
<asp:ListItem Value="D">Delivery Boy</asp:ListItem>
</aspropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="DropDownList3">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th>
<asp:Label ID="Label7" runat="server" Text="Gender"></asp:Label></th>
<td align="left">
<aspropDownList ID="DropDownList2" runat="server" Width="150px" >
<asp:ListItem Value="Female">Female</asp:ListItem>
<asp:ListItem Value="Male">Male</asp:ListItem>
</aspropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox2">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th>
<asp:Label ID="Label8" runat="server" Text="D.O.B"></asp:Label></th>
<td align="left">
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox8">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th>
<asp:Label ID="Label9" runat="server" Text="Department"></asp:Label></th>
<td align="left">
<asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox9">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th class="style1">
<asp:Label ID="Label10" runat="server" Text="Secret Question"></asp:Label></th>
<td align="left" class="style1">
<aspropDownList ID="DropDownList1" runat="server" Width="150px"
Height="32px" >
<asp:ListItem>What is your hobby?</asp:ListItem>
<asp:ListItem>where can we go?</asp:ListItem>
<asp:ListItem>What is your mother's name?</asp:ListItem>
</aspropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="DropDownList1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th>
<asp:Label ID="Labe11" runat="server" Text="Secret Answer"></asp:Label></th>
<td align="left">
<asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox10">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th></th><th></th>
<td align="left">
<asp:Button ID="Button1" OnClick="Button1_Click" runat="server" Text="Submit" />
</td>
</tr>
</table>
<aspqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CourierSystemConnectionString %>"
InsertCommand="Insert_StaffRegis_Table"
InsertCommandType="StoredProcedure"
SelectCommand="SELECT [StaffID], [FirstName], [LastName], [Password], [RetypePass], [Gender], [Designation], [DOB], [Department], [SecretQues], [SecretAns] FROM [StaffRegis_Table]">
<InsertParameters>
<asparameter Name="StaffID" Type="String" />
<asparameter Name="FirstName" Type="String" />
<asparameter Name="LastName" Type="String" />
<asparameter Name="Password" Type="String" />
<asparameter Name="RetypePass" Type="String" />
<asparameter Name="SecretQues" Type="String" />
<asparameter Name="SecretAns" Type="String" />
<asparameter Name="Gender" Type="String" />
<asparameter Name="DOB" Type="String" />
<asparameter Name="Department" Type="String" />
<asparameter Name="Designation" Type="String" />
</InsertParameters>
</aspqlDataSource>
</asp:Content>
![]() |
Similar Threads
- exporting existing excel sheet data into sql database (VB.NET)
- retrieve data from SQL database into a combobox (Visual Basic 4 / 5 / 6)
- How to receive data from SQL database by ODBC class (C++)
- Get data out of excel file stored as an image (MS SQL)
- Problem Inserting into SQL database on server (ASP.NET)
- Display data in separate controls (SQL) (VB.NET)
- Script stores data in wrong MySQL columns (MySQL)
- Help with Roles Stored in SQL database (ASP.NET)
- Snyc'n Local SQL database online (MS SQL)
Other Threads in the ASP.NET Forum
- Previous Thread: ASP.net How to Center Exported image in Excel
- Next Thread: String to Int??
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox click commonfunctions compatible confirmationcodegeneration content contenttype courier css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu dynamically edit expose fill flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery listbox login menu microsoft mono mouse mssql multistepregistration news numerical objects opera order panelmasterpagebuttoncontrols radio ratings registration reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers






ropDownList ID="DropDownList3" runat="server" Width="150px"
qlDataSource ID="SqlDataSource1" runat="server"
arameter Name="StaffID" Type="String" />