Error updating data set

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Hi Phil,

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

I hope this helps,

Cor
 
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.
 
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'."
 
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 said:
Hi Phil,

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

I hope this helps,

Cor
 
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 said:
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 said:
Hi Phil,

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

I hope this helps,

Cor
 
Hi Phil,

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

Cor
 
Back
Top