| | |
Problem updating Database
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 9
Reputation:
Solved Threads: 0
0
#13 Oct 16th, 2009
Well what I did earlier is set my UPDATE statement to
Just to see if the the update statment syntax was correct. It worked it effectively erased the entire Phone column. Wouldn't that mean that I can write to the database?
VB.NET Syntax (Toggle Plain Text)
Update Employee Set Phone = ""
Just to see if the the update statment syntax was correct. It worked it effectively erased the entire Phone column. Wouldn't that mean that I can write to the database?
•
•
Join Date: Sep 2009
Posts: 321
Reputation:
Solved Threads: 45
0
#15 Oct 16th, 2009
Relooking at my example, my syntax was incorrect and I hope you caught this mistake. I didnt use a comma between each of the columns & values and instead used the key word "And". Thats what I get for attempting to code in this webpage textbox... lol
strSQL = "Update [Employee] Set First_Name = @FName, Last_Name = @LName Where Employee_ID = @Id"•
•
•
•
Parameters are pretty easy, I dont know why they dont push it more then the concatenated strings. Below is a quick example and here is a link for some more detailed info Configuring Parameters and Parameter Data Types (ADO.NET)
strSQL = "Update [Employee] Set First_Name = @FName And Last_Name = @LName Where Employee_ID = @Id" command.Transaction = myTransaction command.CommandType = CommandType.Text command.CommandText = strSQL Command.Parameters.AddWithValue("@FName", txtFName.Text) Command.Parameters.AddWithValue("@LName", txtLName.Text) Command.Parameters.AddWithValue("@Id", cint(txtStaffId.Text)) command.ExecuteNonQuery()
0
#16 Oct 16th, 2009
•
•
•
•
Well what I did earlier is set my UPDATE statement to
VB.NET Syntax (Toggle Plain Text)
Update Employee Set Phone = ""
Just to see if the the update statment syntax was correct. It worked it effectively erased the entire Phone column. Wouldn't that mean that I can write to the database?
•
•
Join Date: Oct 2009
Posts: 9
Reputation:
Solved Threads: 0
0
#17 Oct 16th, 2009
So here is my code as it stands now. The update statement is setup according to the way TomW recommended. But I still get the error "Syntax error in the UPDATE statement."
VB.NET Syntax (Toggle Plain Text)
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim myTransaction As System.Data.OleDb.OleDbTransaction Try ' Declares connection and variables and opens connection to database Dim conn As New OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" & _ "Data Source=C:\Users\Christopher Carr\Documents\Visual Studio 2008\WebSites\MYTPSS new\App_Data\tpsDatabase.accdb") conn.Open() Dim command As OleDbCommand = conn.CreateCommand() Dim strSQL As String ' Adds and New Transaction myTransaction = conn.BeginTransaction ' Sets what strSQL display value is strSQL = "Update Employee Set First_Name = @FirstName, Last_Name = @LastName, Phone = @Phone, E-mail = @Email, Address = @Address, Availability = @Availability Where Employee_ID = @EmployeeID" ' Gets a value indicating how the CommandText property is to be interpreted and CommandText is set equal to the strSQL value command.CommandType = CommandType.Text command.CommandText = strSQL ' Starts the transaction command.Transaction = myTransaction command.Parameters.AddWithValue("@FirstName", txtFirstName.Text) command.Parameters.AddWithValue("@LastName", txtLastName.Text) command.Parameters.AddWithValue("@Phone", txtPhone.Text) command.Parameters.AddWithValue("@Email", txtEmail.Text) command.Parameters.AddWithValue("@Address", txtAddress.Text) command.Parameters.AddWithValue("@Availability", txtAvailability.Text) command.Parameters.AddWithValue("@EmployeeID", CInt(txtStaffID.Text)) ' Performs the cataloging operations for update, insert and delete statements command.ExecuteNonQuery() ' Commits or saves transaction to the database myTransaction.Commit() ' Closes the connection to the database conn.Close() lblError.Text = "Your profile was successfully updated." Catch ex As Exception lblError.Text = ex.Message myTransaction.Rollback() End Try End Sub
•
•
Join Date: Sep 2009
Posts: 321
Reputation:
Solved Threads: 45
0
#18 Oct 16th, 2009
Try taking out the conn.createcommand
VB.NET Syntax (Toggle Plain Text)
Dim command As OleDbCommand = new oledbcommand command.Connection = conn
0
#19 Oct 16th, 2009
Access gives weird error messages if you type the wrong column name. Move your query over to the MS Access designer and see if you can run it with the substituted parameter values as a test. I'm almost certain you get a syntax error instead of a "column does not exist" error in updates with access.
•
•
Join Date: Sep 2009
Posts: 321
Reputation:
Solved Threads: 45
0
#20 Oct 16th, 2009
•
•
•
•
Access gives weird error messages if you type the wrong column name. Move your query over to the MS Access designer and see if you can run it with the substituted parameter values as a test. I'm almost certain you get a syntax error instead of a "column does not exist" error in updates with access.
![]() |
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: 1267 | Replies: 28
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code combobox component convert crystalreport data database databasesearch datagrid datagridview design designer dissertation dissertations dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy highlighting images inline insert installer intel internet listview mobile monitor ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project save searchbox searchvb.net select serial server soap sorting studio syntax table tcp text textbox time timer toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf






