473,385 Members | 1,676 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.

Problem in inserting a new row in MS Access using VB.NET

18
Hello,
I'm new in vb.net. I have a problem in inserting a new row to a MS Access database table.
There is no error message comes out when i run my program, but when i check my MS Access table, there is no record inserted. So, i don't know which line is incorrect.

Here is my code:
Dim desc, itemID As String

itemID = txtItemID.Text
desc = txtItemDesc.Text

Dim myOleDbConnection As OleDb.OleDbConnection
Dim insertCommand As String
Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Lecture\CS220\Program backup 3\Ai Ling Ka Salon System\database\login.mdb;User ID=Admin;Password=;"

insertCommand = "INSERT INTO tblLogin (username, password) VALUES(desc, itemID);"

myOleDbConnection = New OleDb.OleDbConnection(myConnectionString)

Dim myOleDbCommand As New OleDb.OleDbCommand(insertCommand, myOleDbConnection)

myOleDbCommand = myOleDbConnection.CreateCommand

myOleDbCommand.CommandType = CommandType.Text

myOleDbCommand.CommandText = insertCommand

myOleDbConnection.Open()

Dim temp_num As Integer
Try
temp_num = myOleDbCommand.ExecuteNonQuery
Catch ex As Exception
Trace.WriteLine(ex.ToString)

End Try

myOleDbConnection.Close()
Thanks...
Jul 16 '07 #1
15 4085
hariharanmca
1,977 1GB
insertCommand = "INSERT INTO tblLogin (username, password) VALUES(desc, itemID);"
Is this desc and item is an variable of front-end.
because

desc is a key word of back-end for Descending order

you cannot pass that as string
Jul 16 '07 #2
yzlin04
18
now i change the 'desc' to 'description', the same case happen again...i can't see my record inside the MS Access table...

Dim description, itemID As String


itemID = txtItemID.Text
description = txtItemDesc.Text

Dim myOleDbConnection As OleDb.OleDbConnection
Dim insertCommand As String
Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Lecture\CS220\Program backup 3\Ai Ling Ka Salon System\database\login.mdb;User ID=Admin;Password=;"

insertCommand = "INSERT INTO tblLogin (username, password) VALUES(description, itemID);"

myOleDbConnection = New OleDb.OleDbConnection(myConnectionString)

Dim myOleDbCommand As New OleDb.OleDbCommand(insertCommand, myOleDbConnection)

myOleDbCommand = myOleDbConnection.CreateCommand

myOleDbCommand.CommandType = CommandType.Text

myOleDbCommand.CommandText = insertCommand

myOleDbConnection.Open()

Dim temp_num As Integer
Try
temp_num = myOleDbCommand.ExecuteNonQuery
Catch ex As Exception
Trace.WriteLine(ex.ToString)

End Try

myOleDbConnection.Close()









Is this desc and item is an variable of front-end.
because

desc is a key word of back-end for Descending order

you cannot pass that as string
Jul 16 '07 #3
hariharanmca
1,977 1GB
now i change the 'desc' to 'description', the same case happen again...i can't see my record inside the MS Access table...

Dim description, itemID As String


itemID = txtItemID.Text
description = txtItemDesc.Text

Dim myOleDbConnection As OleDb.OleDbConnection
Dim insertCommand As String
Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Lecture\CS220\Program backup 3\Ai Ling Ka Salon System\database\login.mdb;User ID=Admin;Password=;"

insertCommand = "INSERT INTO tblLogin (username, password) VALUES(description, itemID);"

myOleDbConnection = New OleDb.OleDbConnection(myConnectionString)

Dim myOleDbCommand As New OleDb.OleDbCommand(insertCommand, myOleDbConnection)

myOleDbCommand = myOleDbConnection.CreateCommand

myOleDbCommand.CommandType = CommandType.Text

myOleDbCommand.CommandText = insertCommand

myOleDbConnection.Open()

Dim temp_num As Integer
Try
temp_num = myOleDbCommand.ExecuteNonQuery
Catch ex As Exception
Trace.WriteLine(ex.ToString)

End Try

myOleDbConnection.Close()
and you never explain what is the error








1. Go to MS access views
2. copy your query and past it in query view
3. then execute it using “!” symbol
4. I think description is also reserved word of database


and copy the error
Jul 16 '07 #4
yzlin04
18
just like the above, there is no error message comes out, so i don't know what is the error.
after i run using "!" symbol, also no error.


and you never explain what is the error








1. Go to MS access views
2. copy your query and past it in query view
3. then execute it using “!” symbol
4. I think description is also reserved word of database


and copy the error
Jul 16 '07 #5
hariharanmca
1,977 1GB
just like the above, there is no error message comes out, so i don't know what is the error.
after i run using "!" symbol, also no error.
change the name descreption
Jul 16 '07 #6
yzlin04
18
it is still the same as before even i have changed the name "description" to "test1"
note: i only have one table (tblLogin) and one query (qryLogin) in MS Access.
both of them are empty.




change the name descreption
Jul 16 '07 #7
hariharanmca
1,977 1GB
it is still the same as before even i have changed the name "description" to "test1"
note: i only have one table (tblLogin) and one query (qryLogin) in MS Access.
both of them are empty.

Refer post #2

and you never explain why you are using description, itemID


if this description, itemID is a string value then you should pass query like

insertCommand = "INSERT INTO tblLogin (username, password) VALUES(‘desc’, ‘itemID’);"
Jul 16 '07 #8
hariharanmca
1,977 1GB
Refer post #2

and you never explain why you are using description, itemID


if this description, itemID is a string value then you should pass query like

insertCommand = "INSERT INTO tblLogin (username, password) VALUES(‘desc’, ‘itemID’);"

i think this is wrong,
login name = Descreption ot test1
password = itemID

just check that
Jul 16 '07 #9
yzlin04
18
i already changed the description to test1.

i use:
- test1 as a name for the txtItemDesc text field value
- itemID refers to the txtItemID text field value, and the ID is not integer, but string.

i pass in the query:

insertCommand = "INSERT INTO tblLogin (username, password) VALUES ('test1', 'itemID');"




Refer post #2

and you never explain why you are using description, itemID


if this description, itemID is a string value then you should pass query like

insertCommand = "INSERT INTO tblLogin (username, password) VALUES(‘desc’, ‘itemID’);"
Jul 16 '07 #10
yzlin04
18
i just use the login.mdb file because both the fields are in text.
And the value i want to insert into the row is also string. so i just use the tblLogin for trying to see whether the code works or not.


i think this is wrong,
login name = Descreption ot test1
password = itemID

just check that
Jul 16 '07 #11
yzlin04
18
hello Hariharanmca...
thanks a lot for your help.
now i can insert a record into the row already, but with the value that i already assigned (static).

but so sorry, i still have another question that i want to ask.
how to insert the value from a textbox into the table row?
because when i try this:

itemID = txtItemID.Text
insertCommand = "INSERT INTO tableTempTransaction (item_Name, quantity, unit_Price, discount, subtotal) VALUES(itemID, '123', '456', '789', '951');"

it doesn't work. no record added in the row.


but when i try this:

insertCommand = "INSERT INTO tableTempTransaction (item_Name, quantity, unit_Price, discount, subtotal) VALUES('itemID', '123', '456', '789', '951');"

it works. but the field is only filled by those value, not the value from the text box.







i think this is wrong,
login name = Descreption ot test1
password = itemID

just check that
Jul 16 '07 #12
hariharanmca
1,977 1GB
i just use the login.mdb file because both the fields are in text.
And the value i want to insert into the row is also string. so i just use the tblLogin for trying to see whether the code works or not.

So, use like this

Expand|Select|Wrap|Line Numbers
  1. insertCommand = "INSERT INTO tblLogin (username, password) 
  2. VALUES( ‘" & strValue1 & "’ , ‘" & strValue2 & "’);"
Jul 16 '07 #13
yzlin04
18
ok...finally it works...
thanks a lot...:)




So, use like this

Expand|Select|Wrap|Line Numbers
  1. insertCommand = "INSERT INTO tblLogin (username, password) 
  2. VALUES( ‘" & strValue1 & "’ , ‘" & strValue2 & "’);"
Jul 16 '07 #14
hariharanmca
1,977 1GB
insertCommand = "INSERT INTO tableTempTransaction (item_Name, quantity, unit_Price, discount, subtotal) VALUES('itemID', '123', '456', '789', '951');"

it works. but the field is only filled by those value, not the value from the text box.
i don't know, why you are using numbers as string?
Jul 16 '07 #15
yzlin04
18
i don't know, why you are using numbers as string?

no, actually i just want to test whether my code works or not. if already can work, i can change it to the value i want.
Thanks
Jul 19 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Not Me | last post by:
Hi, I have a stored procedure, that works perfectly when run from the query analyser, however if I run it through access vba, (using exec) I get a runtime error 208: invalid object name...
3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
0
by: Jindrich Prchal | last post by:
Hi there. We are running DB2 v7.2 for Win NT on Windows 2000 SP3 machine with poor configuration AMD 1800+, 512MB RAM and usual IDE harddisk. During tests of migration our batch programmes...
3
by: Bob Dydd | last post by:
Hi Everybody I have an Access 2000 db with a setup for inserting images in records. I am using the image path only with the actual images stored elswhere on the hard disc. This works perfectly...
0
by: Lyn | last post by:
I am having a frustrating time trying to do a simple insert of a BMP picture into a Bound Object Frame using both VBA and the Insert | Object... dialog. I had a separate post thread going on this...
2
by: Andrew Banks | last post by:
I've got the following code as part of a C# web form but am having problems calling a command. I create a dataset and put some data on the screen. This works fine. (relevant sample below) ...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
5
by: Lyn | last post by:
From time to time I strike a problem where Access will suddenly shut down while running some code (Dr Watson message), wiping out any forensics (diagnostic traces such as debug.prints, etc). This...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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:
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...
0
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...

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.