943,678 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 2073
  • ASP.NET RSS
Nov 16th, 2008
0

insert data Queries.

Expand Post »
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

ASP.NET Syntax (Toggle Plain Text)
  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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
preethi_ga is offline Offline
38 posts
since Jun 2008
Nov 17th, 2008
0

Re: insert data Queries.

do your textboxes have a default value of "mala" and "123"?
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

Re: insert data Queries.

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...
Reputation Points: 12
Solved Threads: 2
Newbie Poster
raj416 is offline Offline
14 posts
since Jan 2008
Nov 18th, 2008
0

Re: insert data Queries.

Click to Expand / Collapse  Quote originally posted by raj416 ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
priyankaa is offline Offline
4 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: how to display the message box in asp.net
Next Thread in ASP.NET Forum Timeline: how to get value of all selected checkbox?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC