| | |
insert data Queries.
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 38
Reputation:
Solved Threads: 0
Hi,
Im using ASP.NET and SQL Server. While inserting the data at run time. the same data , what ever is already in database is being stored again. Say for example, i have empname and empno, "Mala" and 123 already stored in database, if i give new data "Bala" and 124, as soon as i click in insert button, the data's are stored. but Mala and 123 is stored . Even i f i give anyother data. 4 or 5 data i store, again 4 or 5 times the same data repeatedly being stored.
i.e. Mala and 123 is in database for 5 to 6 times. i donno whats wrong with my code.
My code is
Can any one please help me , to solve this?
Im using ASP.NET and SQL Server. While inserting the data at run time. the same data , what ever is already in database is being stored again. Say for example, i have empname and empno, "Mala" and 123 already stored in database, if i give new data "Bala" and 124, as soon as i click in insert button, the data's are stored. but Mala and 123 is stored . Even i f i give anyother data. 4 or 5 data i store, again 4 or 5 times the same data repeatedly being stored.
i.e. Mala and 123 is in database for 5 to 6 times. i donno whats wrong with my code.
My code is
ASP.NET Syntax (Toggle Plain Text)
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Data.OleDb Inherits System.Web.UI.Page Dim con As SqlConnection Dim cmd As SqlCommand Dim cmb As SqlCommandBuilder Dim adp As SqlDataAdapter Dim data As DataSet3 Dim dr As DataRow Dim selct, uptext As String In Page_Load Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try con = New SqlConnection("Data Source=ACER;Initial Catalog=preethi;Integrated Security=True") con.Open() selct = "select * from cooldrinks" adp = New SqlDataAdapter(selct, con) data = New DataSet3() adp.Fill(data, "cooldrinks") fillcontrols() Catch ex As Exception Response.Write(ex.Message) End Try End Sub Private Sub fillcontrols() TextBox1.Text = data.Tables(0).Rows(0).Item(0) TextBox2.Text = data.Tables(0).Rows(0).Item(1) TextBox3.Text = data.Tables(0).Rows(0).Item(2) End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click clearcontrols() End Sub Private Sub clearcontrols() TextBox1.Text = " " TextBox2.Text = " " TextBox3.Text = " " TextBox4.Text = " " TextBox1.Focus() End Sub Protected Sub Insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click Dim Ssql As String Ssql = "insert into cooldrinks(drinkname,color,price)values(@drinkname,@color,@price)" cmd = New SqlCommand(Ssql, con) cmd.Parameters.AddWithValue("@drinkname", TextBox1.Text) cmd.Parameters.AddWithValue("@color", TextBox2.Text) cmd.Parameters.AddWithValue("@price", TextBox3.Text) cmd.ExecuteNonQuery() Response.Write("One Record inserted Successfully") End Sub
Can any one please help me , to solve this?
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
do your textboxes have a default value of "mala" and "123"?
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Apr 2008
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
May be multiple clicks on the button leads to create repeated data in table.You have to redirect current page itself after insertion occurs, or else you have to check record exists in table by select query before insertion...
once executenonquery command is executed clean ur textbox value,and in insert function before inserting data check any one textbox value which is required, that it is blank or not,if blank than exit from function.
![]() |
Similar Threads
- Insert & Edit Data in DataGrid (VB.NET)
- Update and insert query in one (MySQL)
- php/mysql configuration? queries do not return anything. (PHP)
- How to use multiple inserts with transactions in mysql (PHP)
- Nested insert queries in a single query (MySQL)
- MSysTables object error (Visual Basic 4 / 5 / 6)
- Insert Into (PHP)
- nested joins, from mdb. Possible? (Visual Basic 4 / 5 / 6)
- PHP question i think! (Site Layout and Usability)
Other Threads in the ASP.NET Forum
- Previous Thread: how to display the message box in asp.net
- Next Thread: how to get value of all selected checkbox?
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox class click commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu edit expose flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery list listbox login menu microsoft mono mouse mssql multistepregistration nameisnotdeclared news numerical objects order panelmasterpagebuttoncontrols problem radio ratings rotatepage save schoolproject search security serializesmo.table silverlight smartcard sql sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webservice wizard xml youareanotmemberofthedebuggerusers






