473,385 Members | 1,890 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,385 software developers and data experts.

inserting a record into a datagrid?????what is wrong in my code???

Private Sub btnrubriekbij_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnrubriekbij.Click

'insert hier

Dim cn As New OleDb.OleDbConnection(constr)

Dim dc As New OleDb.OleDbCommand

dc.Connection = cn

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid) values
( @soort,@kosten,@datum,@soortid)" ';SELECT soort,kosten,datumfrom tblVast
WHERE (soortid=?)"

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))

daVastBewerkenJ.UpdateCommand = dc

Try

daVastBewerkenJ.Update(dsVastBewerkenJ, "tblVast")

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Open()

dc.ExecuteNonQuery()

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Close()

End Sub

Thanks for helping me out

Hyphessobrycon, the new fish in the vbOcean
Nov 21 '05 #1
4 1138
What's the error message? Just off the top of my head, you're trying to use
named parameters in an OleDb command. Try this:

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid) values
" & _
"( ?, ?, ?, ?);SELECT soort,kosten,datumfrom tblVast " & _
"WHERE (soortid=?)"
dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))
dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))
dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))
dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))
dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid2",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))
"Hyphessobrycon" <sy*********@telenet.be> wrote in message
news:kY*********************@phobos.telenet-ops.be...
Private Sub btnrubriekbij_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnrubriekbij.Click

'insert hier

Dim cn As New OleDb.OleDbConnection(constr)

Dim dc As New OleDb.OleDbCommand

dc.Connection = cn

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid)
values ( @soort,@kosten,@datum,@soortid)" ';SELECT soort,kosten,datumfrom
tblVast WHERE (soortid=?)"

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))

daVastBewerkenJ.UpdateCommand = dc

Try

daVastBewerkenJ.Update(dsVastBewerkenJ, "tblVast")

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Open()

dc.ExecuteNonQuery()

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Close()

End Sub

Thanks for helping me out

Hyphessobrycon, the new fish in the vbOcean

Nov 21 '05 #2

"Hyphessobrycon" <sy*********@telenet.be> wrote in message
news:kY*********************@phobos.telenet-ops.be...
Private Sub btnrubriekbij_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnrubriekbij.Click

'insert hier

Dim cn As New OleDb.OleDbConnection(constr)

Dim dc As New OleDb.OleDbCommand

dc.Connection = cn

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid)
values ( @soort,@kosten,@datum,@soortid)" ';SELECT soort,kosten,datumfrom
tblVast WHERE (soortid=?)"

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))

daVastBewerkenJ.UpdateCommand = dc

Try

daVastBewerkenJ.Update(dsVastBewerkenJ, "tblVast")

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Open()

dc.ExecuteNonQuery()

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Close()

End Sub

Thanks for helping me out

Hyphessobrycon, the new fish in the vbOcean


What is still wrong?? Error message = Signs are found after the insert
instruction
Private Sub btnrubriekbij_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnrubriekbij.Click

'insert hier

Dim cn As New OleDb.OleDbConnection(constr)

Dim dc As New OleDb.OleDbCommand

dc.Connection = cn

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid) values
( ?,?,?,?) ;SELECT soort,kosten,datum,soortid from tblVast WHERE
(soortid=?)"

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid2",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

daVastBewerkenJ.InsertCommand = dc

Try

daVastBewerkenJ.Update(dsVastBewerkenJ, "tblVast")

Catch ex As Exception

MsgBox(ex.Message)

End Try

refreshen_vast()
End Sub

I thank everyone helping that new fish in the vbOcean

Hyphessobrycon
Nov 21 '05 #3
Hmmm. It's apparently picking up the = sign in the WHERE clause. Just for
the heck of it, try dropping the WHERE clause and the last parameter and see
what happens:

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid) " & _
"VALUES ( ?,?,?,?) ;" & _
"SELECT soort,kosten,datum,soortid " & _
"FROM tblVast"
"Hyphessobrycon" <sy*********@telenet.be> wrote in message
news:c3*********************@phobos.telenet-ops.be...

"Hyphessobrycon" <sy*********@telenet.be> wrote in message
news:kY*********************@phobos.telenet-ops.be...
Private Sub btnrubriekbij_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnrubriekbij.Click

'insert hier

Dim cn As New OleDb.OleDbConnection(constr)

Dim dc As New OleDb.OleDbCommand

dc.Connection = cn

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid)
values ( @soort,@kosten,@datum,@soortid)" ';SELECT
soort,kosten,datumfrom tblVast WHERE (soortid=?)"

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))

daVastBewerkenJ.UpdateCommand = dc

Try

daVastBewerkenJ.Update(dsVastBewerkenJ, "tblVast")

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Open()

dc.ExecuteNonQuery()

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Close()

End Sub

Thanks for helping me out

Hyphessobrycon, the new fish in the vbOcean


What is still wrong?? Error message = Signs are found after the insert
instruction
Private Sub btnrubriekbij_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnrubriekbij.Click

'insert hier

Dim cn As New OleDb.OleDbConnection(constr)

Dim dc As New OleDb.OleDbCommand

dc.Connection = cn

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid)
values ( ?,?,?,?) ;SELECT soort,kosten,datum,soortid from tblVast WHERE
(soortid=?)"

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid2",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

daVastBewerkenJ.InsertCommand = dc

Try

daVastBewerkenJ.Update(dsVastBewerkenJ, "tblVast")

Catch ex As Exception

MsgBox(ex.Message)

End Try

refreshen_vast()
End Sub

I thank everyone helping that new fish in the vbOcean

Hyphessobrycon

Nov 21 '05 #4
Hallo Michael,

thank you for helping. I appreciate it greatly.
And I found the solution to my problem .
Since soortid is autonumbering(correct in English?), i had to leave these
parameters out. And also leave that select sentence away. What is it for
anyway??

dc.CommandText = "insert into tblVast ( soort, kosten,datum)
values ( ?,?,?,?)

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))

daVastBewerkenJ.InsertCommand = dc

Hyphessobrycon thanks you very much
"Michael C#" <xy*@yomomma.com> schreef in bericht
news:em*************@TK2MSFTNGP10.phx.gbl... Hmmm. It's apparently picking up the = sign in the WHERE clause. Just
for the heck of it, try dropping the WHERE clause and the last parameter
and see what happens:

c>
"Hyphessobrycon" <sy*********@telenet.be> wrote in message
news:c3*********************@phobos.telenet-ops.be...

"Hyphessobrycon" <sy*********@telenet.be> wrote in message
news:kY*********************@phobos.telenet-ops.be...
Private Sub btnrubriekbij_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnrubriekbij.Click

'insert hier

Dim cn As New OleDb.OleDbConnection(constr)

Dim dc As New OleDb.OleDbCommand

dc.Connection = cn

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid)
values ( @soort,@kosten,@datum,@soortid)" ';SELECT
soort,kosten,datumfrom tblVast WHERE (soortid=?)"

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))

daVastBewerkenJ.UpdateCommand = dc

Try

daVastBewerkenJ.Update(dsVastBewerkenJ, "tblVast")

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Open()

dc.ExecuteNonQuery()

Catch ex As Exception

MsgBox(ex.Message)

End Try

dc.Connection.Close()

End Sub

Thanks for helping me out

Hyphessobrycon, the new fish in the vbOcean

What is still wrong?? Error message = Signs are found after the insert
instruction
Private Sub btnrubriekbij_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnrubriekbij.Click

'insert hier

Dim cn As New OleDb.OleDbConnection(constr)

Dim dc As New OleDb.OleDbCommand

dc.Connection = cn

dc.CommandText = "insert into tblVast ( soort, kosten,datum,soortid)
values ( ?,?,?,?) ;SELECT soort,kosten,datum,soortid from tblVast WHERE
(soortid=?)"

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soort",
System.Data.OleDb.OleDbType.VarChar, 50, "Soort"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("kosten",
System.Data.OleDb.OleDbType.Single, 16, "Kosten"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("datum",
System.Data.OleDb.OleDbType.Date, 12, "Datum"))

dc.Parameters.Add(New System.Data.OleDb.OleDbParameter("soortid2",
System.Data.OleDb.OleDbType.BigInt, 64, "Soortid"))

daVastBewerkenJ.InsertCommand = dc

Try

daVastBewerkenJ.Update(dsVastBewerkenJ, "tblVast")

Catch ex As Exception

MsgBox(ex.Message)

End Try

refreshen_vast()
End Sub

I thank everyone helping that new fish in the vbOcean

Hyphessobrycon


Nov 21 '05 #5

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

Similar topics

0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
7
by: GaryB | last post by:
I have an untyped datatable that has financial numbers and controls that were populated by code (not a simple fill from a DA). Now I want to insert subtotals into it. I wrote a sub to do so that...
5
by: Hennie | last post by:
When trying to update a record in an editable datagrid I ran into a few problems. My update procedure is just not working. Can someone please have a look at my code and see what am I doing wrong....
0
by: hzgt9b | last post by:
Using VS2003, VB.NET, Here's some pseudo code that I'm trying to get to work... if <a specific record existsthen do nothing else <insert the specific record> Endif I've got the code...
0
by: Iain | last post by:
Hi All I have a datagrid which takes it's data from a table on a remote i-series. This datagrid is loaded on Page Load and the user is able to select a record to edit by pressing the...
3
by: rcoco | last post by:
Hi, I want to share this problem. I have a datagrid that will help me Insert data into sql database. So I made a button On my form so that when I press the button a new row on datagrid should be...
10
by: Clamato | last post by:
Good Morning, I'm working with a form that basically add's a users windows logon ID, first name, and last name to a table. A list box on this form is then requeried once added displaying the...
5
by: dos360 | last post by:
Hello, I have two tables, one is a list of activities, the other a list of participants. I want to insert one record in the activities table and then using its identity column as foreign key, I...
3
by: RN1 | last post by:
This is how I am trying to insert a new record in a database table & then display all the records (including the newly inserted record) in a DataGrid: <script runat="server"> Sub...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.