Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 17th, 2004, 07:41 PM
Registered User
 
Join Date: Oct 2004
Location: spartanburg, sc, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shieldsteven Send a message via Yahoo to shieldsteven
Default 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
Reply With Quote
  #2 (permalink)  
Old October 17th, 2004, 11:30 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

What error message you are getting?

Reply With Quote
  #3 (permalink)  
Old October 18th, 2004, 08:43 AM
Registered User
 
Join Date: Oct 2004
Location: spartanburg, sc, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shieldsteven Send a message via Yahoo to shieldsteven
Default

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
Reply With Quote
  #4 (permalink)  
Old October 18th, 2004, 08:49 AM
Registered User
 
Join Date: Oct 2004
Location: spartanburg, sc, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shieldsteven Send a message via Yahoo to shieldsteven
Default

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
Reply With Quote
  #5 (permalink)  
Old October 18th, 2004, 09:40 AM
Friend of Wrox
 
Join Date: Feb 2004
Location: Bangalore, Karnataka, India.
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #6 (permalink)  
Old October 18th, 2004, 10:17 AM
Registered User
 
Join Date: Oct 2004
Location: spartanburg, sc, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shieldsteven Send a message via Yahoo to shieldsteven
Default

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
Reply With Quote
  #7 (permalink)  
Old October 18th, 2004, 11:25 AM
Authorized User
 
Join Date: Jun 2003
Location: Long Island City, NY, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #8 (permalink)  
Old October 18th, 2004, 12:34 PM
Registered User
 
Join Date: Oct 2004
Location: spartanburg, sc, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shieldsteven Send a message via Yahoo to shieldsteven
Default

Quote:
quote: i am using microsoft access 2003
stephen daniel shields
Reply With Quote
  #9 (permalink)  
Old October 20th, 2004, 05:33 PM
Registered User
 
Join Date: Oct 2004
Location: spartanburg, sc, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shieldsteven Send a message via Yahoo to shieldsteven
Default

thanx everyone who tried to help me on this topic
i finally found the solution

stephen daniel shields
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in inserting to Database?? Hannibal Pro JSP 0 March 14th, 2006 07:11 AM
Inserting into a database jroxit Classic ASP Basics 1 January 2nd, 2006 06:04 PM
inserting into database shieldsteven VS.NET 2002/2003 0 November 11th, 2004 07:44 PM
Inserting into database ZiqXx C# 6 July 5th, 2004 04:13 AM
Inserting VBNullChar into a database ipclogistics SQL Language 1 June 11th, 2004 10:10 PM



All times are GMT -4. The time now is 09:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.