473,394 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1480
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.