Click here to Skip to main content
15,896,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dim dr As New DialogResult
dr = MessageBox.Show("Are you sure to update " & Me.cbosoftware.Text & "'s data?", "Notifications", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)


If dr = Windows.Forms.DialogResult.OK Then
provider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\inventory.mdb"
connString = provider
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "update [Soft] set [ID] = '" & idtextboxedit.Text & "' , [Vendor] = '" & vendoredit.Text & "', [Department] = '" & cbodepartment.SelectedValue.ToString() & "', [Last Modified] = '" & Format(edittimepicker.Value, "M/d/yyyy") & "' Where [Title] = '" & cbosoftware.SelectedValue.ToString() & "'"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
cmd.ExecuteNonQuery()
cmd.Dispose()
myConnection.Close()
successadd.ShowDialog()
Posted
Comments
F-ES Sitecore 1-Sep-15 5:43am    
There is nothing in your table that has the Title of what you're searching for. Look at the content of your "str" variable in the debugger and execute it directly against your database using SQL Management Studio\Access, the problem might then become clear, but we don't have access to your database or your inputs so it is impossible to say much more.

Also use parameterised queries, your code is liable to sql injection attacks.

1 solution

For starters, do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
Doing that may cure your problem anyway, but if it doesn't then we would need to know what "not working" actually meant in your context - it could be any error under the sun!

VB
str = "update [Soft] set [ID] = @ID, [Vendor] = @VN, [Department] = @DP, [Last Modified] = @LM Where [Title] = @TT"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
cmd.Parameters.AddWithValue("@ID", idtextboxedit.Text)
cmd.Parameters.AddWithValue("@VN", vendoredit.Text)
cmd.Parameters.AddWithValue("@DP", cbodepartment.SelectedValue.ToString())
cmd.Parameters.AddWithValue("@LM", edittimepicker.Value)
cmd.Parameters.AddWithValue("@TT", cbosoftware.SelectedValue.ToString())
cmd.ExecuteNonQuery()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900