| | |
Problem updating Database
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
0
#21 Oct 17th, 2009
Change SQL Text,
VB.NET Syntax (Toggle Plain Text)
sql="Update Employee Set First_Name = @FirstName, Last_Name = @LastName, Phone = @Phone, [E-mail] = @Email, Address = @Address, Availability = @Availability Where Employee_ID = @EmployeeID"
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
0
#25 Oct 18th, 2009
•
•
•
•
Alright I added the myTransaction.Rollback which was giving me errors but works now for some reason.
I have not used parameters at all before, so can you point me to a good resource to learn how to setup and use parameters. I have already attempted to create my parameters which seems straight forward but how do I actually implement them in the Update Statement?
I haven't said it yet but thanks for the help so far.
Thanks
Musa Prodhan
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
0
#26 Oct 20th, 2009
This code does not produce errors but it does not execute any update.
Any ideas?
Thanks
VB.NET Syntax (Toggle Plain Text)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New SqlConnection Dim cmd As New SqlCommand con.ConnectionString = "Data Source=XXXXXX;Initial Catalog=XXXXX;Persist Security Info=True;User ID=XXXX;Password=XXXX" con.Open() cmd.Connection = con cmd.CommandText = "Update services set service_name = @sName, cost = @sCost, service_desc = @sDesc, cat_rel = @sCatRel Where service_ID = @sID" 'Response.Write(cmd.CommandText) cmd.Parameters.Add(New SqlParameter("@sName", SqlDbType.VarChar, 50)) cmd.Parameters("@sName").Value = txtSername.Text cmd.Parameters.Add(New SqlParameter("@sCost", SqlDbType.VarChar, 50)) cmd.Parameters("@sCost").Value = txtCost.Text cmd.Parameters.Add(New SqlParameter("@sDesc", SqlDbType.Text)) cmd.Parameters("@sDesc").Value = ServDescr.Value cmd.Parameters.Add(New SqlParameter("@sCatRel", SqlDbType.Int)) cmd.Parameters("@sCatRel").Value = CatRel.SelectedValue cmd.Parameters.Add(New SqlParameter("@sID", SqlDbType.Int)) cmd.Parameters("@sID").Value = Request.QueryString("id") cmd.ExecuteNonQuery() Updated.Text = "Your service data was updated successfully!" End Sub
Any ideas?
Thanks
•
•
Join Date: Sep 2009
Posts: 321
Reputation:
Solved Threads: 45
0
#27 Oct 21st, 2009
Chris are you checking the actual database or just your in-memory dataset. Since the coding is directly updating the database with values from textboxes rather then first adding a new datarow to the dataset/datatable, you will not see the changes in the dataset/datatable until the next time you perform a fill operation.
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
So below I am populating the form with the original data on the load
event then updating the database and the form is reloading on postback.
I just thought to myself that maybe the problem is with the load event. Maybe I am updating the DB with the original data and that is why I am not getting errors yet noithing is being updated?
event then updating the database and the form is reloading on postback.
I just thought to myself that maybe the problem is with the load event. Maybe I am updating the DB with the original data and that is why I am not getting errors yet noithing is being updated?
VB.NET Syntax (Toggle Plain Text)
Imports System.Data Imports System.Data.SqlClient Partial Class admin_service_edit Inherits System.Web.UI.Page 'write database data to form on initial load Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim con As String = "Data Source=xxx;Initial Catalog=xxx;Persist Security Info=True;User ID=xxx;Password=xxx" Dim cmd As New SqlCommand Dim pId As Integer pId = Request.QueryString("id") cmd.CommandText = "Select * from services where service_ID = '" & pId & "'" cmd.Connection = New SqlConnection(con) cmd.Connection.Open() Dim dr As SqlDataReader = cmd.ExecuteReader() While dr.Read() txtSername.Text = dr("service_name") txtCost.Text = dr("cost") ServDescr.Value = dr("service_desc") CatRel.SelectedValue = dr("cat_rel") End While cmd.Connection.Close() End Sub 'on button click update the database record Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim mycon As New SqlConnection Dim mycommand As New SqlCommand mycon.ConnectionString = "Data Source=xxx;Initial Catalog=xxx;Persist Security Info=True;User ID=xxx;Passwordxxx" mycon.Open() mycommand.Connection = mycon Try mycommand.CommandText = "Update services set service_name = @sName, cost = @sCost, service_desc = @sDesc, cat_rel = @sCatRel Where service_ID = @sID" 'Response.Write(mycommand.CommandText) mycommand.Parameters.AddWithValue("@sName", txtSername.Text) mycommand.Parameters.AddWithValue("@sCost", txtCost.Text) mycommand.Parameters.AddWithValue("@sDesc", ServDescr.Value) mycommand.Parameters.AddWithValue("@sCatRel", CatRel.SelectedValue) mycommand.Parameters.AddWithValue("@sID", Request.QueryString("id")) 'mycommand.Parameters.Add(New SqlParameter("@sName", SqlDbType.VarChar, 50)) 'mycommand.Parameters("@sName").Value = txtSername.Text 'mycommand.Parameters.Add(New SqlParameter("@sCost", SqlDbType.VarChar, 50)) 'mycommand.Parameters("@sCost").Value = txtCost.Text 'mycommand.Parameters.Add(New SqlParameter("@sDesc", SqlDbType.Text)) 'mycommand.Parameters("@sDesc").Value = ServDescr.Value 'mycommand.Parameters.Add(New SqlParameter("@sCatRel", SqlDbType.Int)) 'mycommand.Parameters("@sCatRel").Value = CatRel.SelectedValue 'mycommand.Parameters.Add(New SqlParameter("@sID", SqlDbType.Int)) 'mycommand.Parameters("@sID").Value = Request.QueryString("id") mycommand.ExecuteNonQuery() Updated.Text = "Your service data was updated successfully!" Catch ex As Exception Updated.Text = ex.Message MsgBox(ex.Message) End Try mycommand.Connection.Close() End Sub End Class
•
•
Join Date: Sep 2009
Posts: 321
Reputation:
Solved Threads: 45
0
#29 Oct 21st, 2009
Again I would ask are you sure the record is not being updated in the actual database and your just not seeing it on the front end? I dont see where its doing a refill of the new data except in the page load. Also have you stepped thru the code to see the exact values that are in the parameter variables at the time it is executed; it might be something unexpected?
I would change your fill in the page load, to fill a form/global scope level dataset rather then using a reader to store the values in your controls. Then in your update button, I would make the update to the existing record in your dataset. Then call the update method of the dataadapter to update the database on the entire dataset.
I would change your fill in the page load, to fill a form/global scope level dataset rather then using a reader to store the values in your controls. Then in your update button, I would make the update to the existing record in your dataset. Then call the update method of the dataadapter to update the database on the entire dataset.
![]() |
Similar Threads
- Database not being updated after DataAdapter.Update (C#)
- Problem with updating database after delete or edit (VB.NET)
- NEED HELP complicated problem with the design of a database (Database Design)
- I am New In MySQL. Problem With MySQL Database Plz Help. (MySQL)
- Updating database with related tables and queries?? (VB.NET)
- Error connecting to database (ASP.NET)
- Re: Problem in updating project for Microsoft Project 2002 and 2003 (Windows Software)
Other Threads in the VB.NET Forum
- Previous Thread: WM Browser
- Next Thread: cmd.executenonquery not accepting nz function
Views: 1269 | Replies: 28
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 2008 access add application array assignment basic box button buttons center class click code combo convert cpu data database datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees error excel exists firewall function image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan picturebox port print printing printpreview problem record refresh regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase storedprocedure string structures studio temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet vista visual visualbasic visualbasic.net visualstudio2008 web wpf xml






