| | |
Update record Problem.
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 38
Reputation:
Solved Threads: 0
Hi Everyone,
Im using ASP.NET and SQL Server. I have Insert , delete data working well. but if i update a particular record it just all the records are updated with the same value.
for example if i have 3 records with 3 different values, if i display the second record, and edit it, and update it. then all the 3 values are updated with the same value what i have entered. i donno what is the error in my code. can anyone enlighten me?
here is the code,
Im using ASP.NET and SQL Server. I have Insert , delete data working well. but if i update a particular record it just all the records are updated with the same value.
for example if i have 3 records with 3 different values, if i display the second record, and edit it, and update it. then all the 3 values are updated with the same value what i have entered. i donno what is the error in my code. can anyone enlighten me?
here is the code,
ASP.NET Syntax (Toggle Plain Text)
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Data.OleDb Partial Class Default7 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 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load con = New SqlConnection("Data Source=ACER;Initial Catalog=preethi;Integrated Security=True") con.Open() 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 Update_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Try uptext = "update cooldrinks set drinkname = @drinkname ,color = @color, price = @price" cmd = New SqlCommand(uptext, con) cmd.Parameters.AddWithValue("@drinkname", TextBox1.Text) cmd.Parameters.AddWithValue("@color", TextBox2.Text) cmd.Parameters.AddWithValue("@price", TextBox3.Text) cmd.ExecuteNonQuery() Response.Write("Data Updated Successfully") Catch ex As Exception Response.Write(ex.Message) End Try End Sub Protected Sub AddNew_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 = " " TextBox1.Focus() End Sub Protected Sub Insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click Dim Ssql As String Try 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() clearcontrols() Catch ex As Exception Response.Write(ex.Message) End Try Response.Write("One Record inserted Successfully") End Sub Protected Sub Delete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click Dim Ssql As String Ssql = "delete from cooldrinks where price = @price " cmd = New SqlCommand(Ssql, con) cmd.Parameters.AddWithValue("@price", TextBox3.Text) cmd.ExecuteNonQuery() Response.Write("Deleted") End Sub Protected Sub LoadTable_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click Try 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 End Class
It is so obvious that you dont have any where condition in the update statement.
uptext = "update cooldrinks set drinkname = @drinkname ,color = @color, price = @price" --> You need to add the where clause here.
uptext = "update cooldrinks set drinkname = @drinkname ,color = @color, price = @price" --> You need to add the where clause here.
•
•
Join Date: Jun 2008
Posts: 38
Reputation:
Solved Threads: 0
hi,
i gave Update Sql Command, but its not working.
this is the code i have given.....
i gave Update Sql Command, but its not working.
this is the code i have given.....
ASP.NET Syntax (Toggle Plain Text)
uptext = "update cooldrinks set drinkname = @drinkname ,color = @color, price = @price where price = " & TextBox3.Text & " "
Last edited by peter_budo; Dec 17th, 2008 at 8:12 pm. Reason: Use [code] tag not [tex]
•
•
Join Date: Jun 2008
Posts: 38
Reputation:
Solved Threads: 0
hi,
i gave Update Sql Command, but its not working.
this is the code i have given.....
i gave Update Sql Command, but its not working.
this is the code i have given.....
ASP.NET Syntax (Toggle Plain Text)
uptext = "update cooldrinks set drinkname = @drinkname ,color = @color, price = @price where price = " & TextBox3.Text & " "
•
•
•
•
hi,
i gave Update Sql Command, but its not working.
this is the code i have given.....
ASP.NET Syntax (Toggle Plain Text)
uptext = "update cooldrinks set drinkname = @drinkname ,color = @color, price = @price where price = " & TextBox3.Text & " "
![]() |
Similar Threads
- vb6 update record in the database (Visual Basic 4 / 5 / 6)
- Problem with Update Record in MS ACCESS (VB.NET)
- updating database problem (PHP)
- Updating a record in an MS Access database file using DataSets (VB.NET)
- Problem when adding delete confirmation (ASP)
- update but not updated (ASP.NET)
- Select + update not working together (ASP)
- Problem with update data to database (JSP)
- retreive and update from check boxes (ColdFusion)
- SQL Delete/Update Error (ColdFusion)
Other Threads in the ASP.NET Forum
- Previous Thread: How to create Check Box Controls list in Repeater/Datalist/Listview ??
- Next Thread: IIS
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos application asp asp.net bc30451 bottomasp.net box browser button c# c#gridviewcolumn checkbox click commonfunctions compatible confirmationcodegeneration content courier css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose fileuploader fill flash form formatdecimal forms formview gridview gudi homeedition hosting iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security select silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking typeof unauthorized validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers





