insert data Queries.

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 38
Reputation: preethi_ga is an unknown quantity at this point 
Solved Threads: 0
preethi_ga preethi_ga is offline Offline
Light Poster

insert data Queries.

 
0
  #1
Nov 16th, 2008
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

  1. Imports System
  2. Imports System.Data
  3. Imports System.Data.SqlClient
  4. Imports System.Data.OleDb
  5.  
  6. Inherits System.Web.UI.Page
  7. Dim con As SqlConnection
  8. Dim cmd As SqlCommand
  9. Dim cmb As SqlCommandBuilder
  10. Dim adp As SqlDataAdapter
  11. Dim data As DataSet3
  12. Dim dr As DataRow
  13. Dim selct, uptext As String
  14.  
  15. In Page_Load
  16.  
  17. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  18. Try
  19. con = New SqlConnection("Data Source=ACER;Initial Catalog=preethi;Integrated Security=True")
  20. con.Open()
  21. selct = "select * from cooldrinks"
  22. adp = New SqlDataAdapter(selct, con)
  23. data = New DataSet3()
  24. adp.Fill(data, "cooldrinks")
  25. fillcontrols()
  26. Catch ex As Exception
  27. Response.Write(ex.Message)
  28. End Try
  29. End Sub
  30.  
  31. Private Sub fillcontrols()
  32. TextBox1.Text = data.Tables(0).Rows(0).Item(0)
  33. TextBox2.Text = data.Tables(0).Rows(0).Item(1)
  34. TextBox3.Text = data.Tables(0).Rows(0).Item(2)
  35. End Sub
  36.  
  37.  
  38. Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
  39. clearcontrols()
  40. End Sub
  41.  
  42.  
  43. Private Sub clearcontrols()
  44. TextBox1.Text = " "
  45. TextBox2.Text = " "
  46. TextBox3.Text = " "
  47. TextBox4.Text = " "
  48. TextBox1.Focus()
  49. End Sub
  50.  
  51.  
  52. Protected Sub Insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
  53. Dim Ssql As String
  54. Ssql = "insert into cooldrinks(drinkname,color,price)values(@drinkname,@color,@price)"
  55. cmd = New SqlCommand(Ssql, con)
  56. cmd.Parameters.AddWithValue("@drinkname", TextBox1.Text)
  57. cmd.Parameters.AddWithValue("@color", TextBox2.Text)
  58. cmd.Parameters.AddWithValue("@price", TextBox3.Text)
  59. cmd.ExecuteNonQuery()
  60. Response.Write("One Record inserted Successfully")
  61.  
  62. End Sub

Can any one please help me , to solve this?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: insert data Queries.

 
0
  #2
Nov 17th, 2008
do your textboxes have a default value of "mala" and "123"?
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 14
Reputation: raj416 is an unknown quantity at this point 
Solved Threads: 2
raj416 raj416 is offline Offline
Newbie Poster

Re: insert data Queries.

 
0
  #3
Nov 18th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 4
Reputation: priyankaa is an unknown quantity at this point 
Solved Threads: 0
priyankaa priyankaa is offline Offline
Newbie Poster

Re: insert data Queries.

 
0
  #4
Nov 18th, 2008
Originally Posted by raj416 View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC