| | |
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 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash flv formview gridview gudi iis javascript list listbox menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice wizard xsl





