 |
| VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1).
** Please don't post code questions here **
For issues specific to a particular language in .NET, please see the other forum categories. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 17th, 2004, 07:41 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
inserting into database
below is the code i'm using to try to insert a new row and everysite ive visited says that this is the correct method but when the compiler gets to the executenonquery command it gives me a exception error message and i dont understand what the problem can be
can any one tell me what is wrong with the code i pasted below.
all help is appreciated
Dim myconnection2 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;" & "Data Source=C:\Documents and Settings\shields\My Documents\admingraphics_backup\MATHDB.MDB")
Dim myolecommand As OleDbCommand
myolecommand = New OleDbCommand("INSERT INTO TUTORLOG(TUTORNUMBER , DATE, LASTNAME,DISCIPLINE, LOGINTIME,SUBJECTS) VALUES('" & strtutor & "','" & thedate & "','" & lname & "','" & fname & "','" & disci & "','" & theTime & "','" & "STEVEN')", myconnection2)
myconnection2.Open()
myolecommand.ExecuteNonQuery()
stephen daniel shields
|
|

October 17th, 2004, 11:30 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What error message you are getting?
|
|

October 18th, 2004, 08:43 AM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by Santhi
What error message you are getting?
|
Quote:
quote: i am getting this error message
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
|
stephen daniel shields
|
|

October 18th, 2004, 08:49 AM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote: heres all of my code so ull know what everything means
Dim myconnection2 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;" & "Data Source=C:\Documents and Settings\shields\My Documents\admingraphics_backup\MATHDB.MDB")
Dim myadapter As New OleDb.OleDbDataAdapter("select * from tutorlog", myconnection2)
Dim dataset2 As New DataSet
'Dim cmd As OleDb.OleDbCommand
'Dim ssql As String
Dim position As Integer
Dim newpos As String
newpos = CStr(position)
myadapter.Fill(dataset2, "tutorinfo")
position = dataset2.Tables("tutorinfo").Rows.Count + 1
strtutor = strtutor & CStr(newpos)
Dim lname = txtlname.Text.ToUpper()
Dim fname = txtfstname.Text.ToUpper()
Dim disci = lbxdisc.Text.ToUpper
Dim datenow As Date = Today
Dim timeNow As Date = Now
Dim theTime As String = FormatDateTime(timeNow, DateFormat.ShortTime)
Dim thedate As String = FormatDateTime(datenow, DateFormat.ShortDate)
Dim message As String
Dim myconnection3 As OleDbConnection
Dim myolecommand As OleDbCommand
myconnection3 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=C:\Documents and Settings\shields\My Documents\admingraphics_backup\MATHDB.MDB")
message = "INSERT INTO TUTORLOG(TUTORNUMBER, DATE, LASTNAME, DISCIPLINE, LOGINTIME) VALUES("
message += strtutor & ","
message += thedate & ","
message += lname & ","
message += fname & ","
message += disci & ","
message += theTime & ")"
myconnection3.Open()
myolecommand = New OleDbCommand(message, myconnection3)
myolecommand.ExecuteNonQuery()
myconnection3.Close()
|
stephen daniel shields
|
|

October 18th, 2004, 09:40 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You haven't opened the database connection, please use
myconnection2.open();
Now try and let me know if it works!
It is not how much we do,
but how much love we put in the doing.
-Mother Theresa
|
|

October 18th, 2004, 10:17 AM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
quote: if you look at the code, i named it myconnection3 and i opened it but i changed it to myconnection2.open() '; cant be used bc its vb.net' and it gives me the same error message. thanx for trying to help though. more answers are appreciated
|
stephen daniel shields
|
|

October 18th, 2004, 11:25 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What version of Access are you using for your database? 97, 2000, XP, 2003? If you are using 97 you can't use Microsoft.Jet.OLEDB.4.0 you need to use Microsoft.Jet.OLEDB.3.51.
|
|

October 18th, 2004, 12:34 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
quote: i am using microsoft access 2003
|
stephen daniel shields
|
|

October 20th, 2004, 05:33 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanx everyone who tried to help me on this topic
i finally found the solution
stephen daniel shields
|
|
 |