473,491 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error updating data set

Hi,

I'm new to '.net'. I'm working in vb.net and have an error don't know the cause of or how I should go about debugging it.

Here is the code:

Dim dsNwind As New DataSet
Dim daProds As New SqlDataAdapter(cmdSelProds)

daProds.Fill(dsNwind, "Prods")

Dim drProd As DataRow
drProd = dsNwind.Tables("Prods").NewRow

drProd.Item("ProductId") = 1006
drProd.Item("Name") = "widget"
drProd.Item("Grams") = "11g"
drProd.Item("Percent") = 5

dsNwind.Tables("Prods").Rows.Add(drProd)

daProds.Update(dsNwind, "Prods")

The last line of code produces the error:

"Incorrect syntax near the keyword 'Percent'."

I tried commenting out the line :

drProd.Item("Percent") = 5

but still got the same error.

Any help is appreciated.
Thanks,
Phil
Jul 21 '05 #1
6 1483
Hi Phil,

That is mostly with sql words try it everywhere with [Percent]

I hope this helps,

Cor
Jul 21 '05 #2
first of all, the syntax error is in the INSERT statement in the
DataAdapter. Since you didn't use a CommandBuilder, I don't see where
that statement came from.

Phil wrote:
Hi,

I'm new to '.net'. I'm working in vb.net and have an error don't know the cause of or how I should go about debugging it.

Here is the code:

Dim dsNwind As New DataSet
Dim daProds As New SqlDataAdapter(cmdSelProds)

daProds.Fill(dsNwind, "Prods")

Dim drProd As DataRow
drProd = dsNwind.Tables("Prods").NewRow

drProd.Item("ProductId") = 1006
drProd.Item("Name") = "widget"
drProd.Item("Grams") = "11g"
drProd.Item("Percent") = 5

dsNwind.Tables("Prods").Rows.Add(drProd)

daProds.Update(dsNwind, "Prods")

The last line of code produces the error:

"Incorrect syntax near the keyword 'Percent'."

I tried commenting out the line :

drProd.Item("Percent") = 5

but still got the same error.

Any help is appreciated.
Thanks,
Phil

Jul 21 '05 #3
Hi Cor,
Thanks for the response.That doesn't seem to be the problem.

I changed the code to use the square brackets and take the percent out and still got the same error in the same spot.
This is the updated code:
Dim cmdSelProds As New SqlCommand("select ProductId, Name,Grams,[Percent] as pr" & _
" from ProductDetails", cnNwind)
Dim dsNwind As New DataSet
Dim daProds As New SqlDataAdapter(cmdSelProds)

Try

daProds.Fill(dsNwind, "Prods")

Dim drProd As DataRow
drProd = dsNwind.Tables("Prods").NewRow

drProd.Item("ProductId") = 1006
drProd.Item("Name") = "widget"
drProd.Item("Grams") = "11g"
''''''drProd.Item("Percent") = 5
drProd.Item("pr") = 5

dsNwind.Tables("Prods").Rows.Add(drProd)

Dim cbProd As New SqlCommandBuilder(daProds)

daProds.Update(dsNwind, "Prods")

I still get the same error at the same line (the last line) :

"Incorrect syntax near the keyword 'Percent'."

"Cor Ligthert" wrote:
Hi Phil,

That is mostly with sql words try it everywhere with [Percent]

I hope this helps,

Cor

Jul 21 '05 #4
Hi Phil,

I could not see that in the previous message, however I do not know a table
in northwind with the name ProductDetails, did you made that yourself or
where is my mistake?

Mostly when you search on ProductDetails and northwind on MSDN you will get
a hit, however I get nothing.

Cor
Thanks for the response.That doesn't seem to be the problem.

I changed the code to use the square brackets and take the percent out and still got the same error in the same spot. This is the updated code:
Dim cmdSelProds As New SqlCommand("select ProductId, Name,Grams,[Percent] as pr" & _ " from ProductDetails", cnNwind)
Dim dsNwind As New DataSet
Dim daProds As New SqlDataAdapter(cmdSelProds)

Try

daProds.Fill(dsNwind, "Prods")

Dim drProd As DataRow
drProd = dsNwind.Tables("Prods").NewRow

drProd.Item("ProductId") = 1006
drProd.Item("Name") = "widget"
drProd.Item("Grams") = "11g"
''''''drProd.Item("Percent") = 5
drProd.Item("pr") = 5

dsNwind.Tables("Prods").Rows.Add(drProd)

Dim cbProd As New SqlCommandBuilder(daProds)

daProds.Update(dsNwind, "Prods")

I still get the same error at the same line (the last line) :

"Incorrect syntax near the keyword 'Percent'."

"Cor Ligthert" wrote:
Hi Phil,

That is mostly with sql words try it everywhere with [Percent]

I hope this helps,

Cor

Jul 21 '05 #5
Hi Cor,

What happened is I'm working through an exercise in a text that uses Northwind as a database, but since I don't have Northwind, I'm using one called db_grocertogo (which has a table productDetails). I've got northwind in my code though because I didn't bother changing the names of the variables I'm using.

Regards,
Phil

"Cor Ligthert" wrote:
Hi Phil,

I could not see that in the previous message, however I do not know a table
in northwind with the name ProductDetails, did you made that yourself or
where is my mistake?

Mostly when you search on ProductDetails and northwind on MSDN you will get
a hit, however I get nothing.

Cor
Thanks for the response.That doesn't seem to be the problem.

I changed the code to use the square brackets and take the percent out and

still got the same error in the same spot.
This is the updated code:
Dim cmdSelProds As New SqlCommand("select ProductId,

Name,Grams,[Percent] as pr" & _
" from ProductDetails", cnNwind)
Dim dsNwind As New DataSet
Dim daProds As New SqlDataAdapter(cmdSelProds)

Try

daProds.Fill(dsNwind, "Prods")

Dim drProd As DataRow
drProd = dsNwind.Tables("Prods").NewRow

drProd.Item("ProductId") = 1006
drProd.Item("Name") = "widget"
drProd.Item("Grams") = "11g"
''''''drProd.Item("Percent") = 5
drProd.Item("pr") = 5

dsNwind.Tables("Prods").Rows.Add(drProd)

Dim cbProd As New SqlCommandBuilder(daProds)

daProds.Update(dsNwind, "Prods")

I still get the same error at the same line (the last line) :

"Incorrect syntax near the keyword 'Percent'."

"Cor Ligthert" wrote:
Hi Phil,

That is mostly with sql words try it everywhere with [Percent]

I hope this helps,

Cor


Jul 21 '05 #6
Hi Phil,

Forget my last message, what happens when you take that percent completly
out of your code, only to try?

Cor
Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7801
by: azgoddess1 | last post by:
During the installation I get these error messages: ***** SQL1390C The environment variable DB2Instance is not defined or is invalid An error ocured while loading the command "C:\Program...
18
9006
by: Steve | last post by:
Hi I have a really weird problem and any assistance would be welcome. I have developed an app in Access 2002. The app runs perfectly on the development machine. I have packaged the app using...
14
2911
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
3
616
by: amatuer | last post by:
ADODB.Recordset error '800a0cb3' Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype. /devag/newProjSave.asp, line 321 ...
11
12378
by: gnortenjones | last post by:
I have a linked table (to an oracle db), and I am trying to run a simple update query against it to change some data, but I am getting the following error: "...didn't update 0 fields due to a type...
3
1857
by: Trez | last post by:
Hey guys, Am new at using ASP.Net. am having some problems updating my SQL DB. whenever i try i get this Error. Can someone help me? Incorrect syntax near 'nvarchar'. Description: An unhandled...
10
1672
by: Mike | last post by:
I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I'm passing an INT to my method to update the record. My code is working though I'm still getting an...
0
2893
by: mbenedict | last post by:
I am rather new at this code and am attempting to modify existing code to use clob datatypes, which I have never used before. The database tables have been set up for clob data. When trying to use...
2
1811
by: Smurfas | last post by:
What's wrong? Compiletor don't show anything, but whet I start program show this error: "Error updating the employee details!" protected void Button1_Click(object sender, EventArgs e) ...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.