Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi! Can someone help me? I'm stuck with this code, when I start to choose an item in combobox the error shows. This is CRUD operation, I'm trying to fix this many times but still give an error. How do I fix this? The user information must be shown in Datagridview after they click the add button.


status1 and categ are combobox.

What I have tried:

Private Sub add1_Click(sender As Object, e As EventArgs) Handles Insert.Click

ds = New DataSet
adapter = New OleDbDataAdapter("insert into [tblmerchant] ([DESCRIPTION],[PRICE],[STATUS], [CATEGORIES], [IMAGE PATH]) VALUES " &
"('" & descrip.Text & "','" & price.Text & "','" & status1.SelectedItem.ToString() & "','" & categ.SelectedItem.ToString() & "','" & path1.Text & "')", conn)



adapter.Fill(ds, "tblmerchant")
GetRecords()
Posted
Updated 3-Nov-22 2:08am
v3
Comments
Richard MacCutchan 2-Nov-22 8:04am    
No one can help you unless you tell us exactly what the error is and where it occurs.
Richard Deeming 2-Nov-22 8:16am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.

1 solution

See the comments to your previous question How to check empty fields using VB.NET[^]

1. You were told to use Parameterised queries. Apart from avoiding SQL Injection, using parameters very often makes other issues "go away". Highly likely that this will solve part of your problem here.

2. You were also told
Quote:
Then we move on to the fact that you're using a DataAdapter to fill a DataSet, but the query you're executing is an INSERT, which doesn't return any records. You should use an OleDbCommand and call ExecuteNonQuery instead.
If you don't apply the advice you are given then members will very quickly just stop trying to help you at all. Fix these two issues and try again.
 
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