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...
15 4085
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
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
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
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
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
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
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’);"
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
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’);"
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
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
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 - insertCommand = "INSERT INTO tblLogin (username, password)
-
VALUES( ‘" & strValue1 & "’ , ‘" & strValue2 & "’);"
ok...finally it works...
thanks a lot...:)
So, use like this - insertCommand = "INSERT INTO tblLogin (username, password)
-
VALUES( ‘" & strValue1 & "’ , ‘" & strValue2 & "’);"
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?
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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)
...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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...
| |