Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics 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
 
Old May 16th, 2007, 05:21 AM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB Noob - Little syntax help

Hi, Thanks for taking a look.

Im tryig to write a little stock program, and i keep getting the following error
System.Runtime.InteropServices.COMException was unhandled
  ErrorCode=-2146825287
  HelpLink="C:\Windows\HELP\ADO270.CHM#1240641"
  Message="Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."
  Source="ADODB.Recordset"

at this line of code

rsRecordSet.Source = ("Select * from Suppliers")

Im using VB 2005 express edition. Can any tell this noob where he has gone wrong, Thanks


Module Module2
    Public SupCount As Integer
    Public Supplier As String
    Public connConnection As ADODB.Connection
    Public rsRecordSet As ADODB.Recordset
    Public mblnAddMode As Boolean
    Public strConnect As String
    Public strProvider As String
    Public strDataSource As String
    Public strDataBaseName As String

    Public Sub GetSuppliers()
        Supplier = ""
        SupCount = 0
        strProvider = "Provider= Microsoft.Jet.OLEDB.3.51;"
        strDataSource = "C:\"
        strDataBaseName = "db1.MDB"
        strDataSource = "Data Source=" & strDataSource & _
            strDataBaseName
        strConnect = strProvider & strDataSource
        connConnection = New ADODB.Connection
        connConnection.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        connConnection.Open(strConnect)
        rsRecordSet = New ADODB.Recordset
        rsRecordSet.CursorType = ADODB.CursorTypeEnum.adOpenStatic
        rsRecordSet.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        rsRecordSet.LockType = ADODB.LockTypeEnum.adLockPessimistic
        rsRecordSet.ActiveConnection = connConnection
        rsRecordSet.Source = ("Select * from Suppliers")

        rsRecordSet.Open()
        rsRecordSet.MoveFirst()
        For SupCount = 0 To 2
            Supplier = rsRecordSet.Fields(0).Value & " " & rsRecordSet.Fields(1).Value
            Form2.ListBox1.Items.Add(Supplier)
            Supplier = ""
        Next

    End Sub
End Module


Error Stack Trace

StackTrace:
       at ADODB.RecordsetClass.set_Source(Object pvSource)
       at WindowsApplication1.Module2.GetSuppliers() in C:\Users\RDX100\Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplicati on1\Module2.vb:line 29
       at WindowsApplication1.Form2.Form2_Load(Object sender, EventArgs e) in C:\Users\RDX100\Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplicati on1\Form2.vb:line 8
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
       at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow( HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolea n value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.Show()
       at WindowsApplication1.Form3.Button7_Click(Object sender, EventArgs e) in C:\Users\RDX100\Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplicati on1\Form3.vb:line 119
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[] commandLine)
       at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
       at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()


 
Old May 16th, 2007, 07:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

besides that I don't know why are you using a vb 6 method to access a database from vb.net (I suggest you read about the objects that are inside .net and allow you to connect to a database..), you can try taking out the 2 lines that set the cursor location (sometimes it makes code fail), I refer to:
Code:
connConnection.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rsRecordSet.CursorLocation = ADODB.CursorLocationEnum.adUseClient
HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 16th, 2007, 12:22 PM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmm still not working.

so im trying the vb 2005 database the book i read said to select the

Microsoft Access Database File (OLE DB) from the drop down when creating a connection but it only has .net framwork dataprovider for oledb ?

Am I missing some of the program install??

 
Old May 16th, 2007, 12:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

I don't know how the express edition work.. don't you have and access data provider??? maybe you did miss some installs feature....

anyway the code for sure in the book is not written like that...

connection should be of type system.data.oledb.oledbconnection...

and recordset are deprecated in this version, you should try dataset and datatables.. and in your case a datareader will work...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 16th, 2007, 05:17 PM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cheers for the help :)

I found this code and modified it.

now i just got find out how to write back to a an access DB


Public I As Integer = 0
    Public StrSupCode(100000) As String
    Public StrName(100000) As String
    Public strAboutVBConn As String = _
            "Provider=Microsoft.Jet.OLEDB.4.0;" _
            & "User ID=Admin;" _
            & "Data Source=C:\db1.mdb"
    Public ocmdAboutVBCommand As OleDbCommand
    Public odtrAboutVBDataReader As OleDbDataReader
    Public Sub GetSuppliers()
        ocmdAboutVBCommand = New OleDbCommand()
        With ocmdAboutVBCommand
            .Connection = New OleDbConnection(strAboutVBConn)
            .Connection.Open()
            .CommandText = "Select * From Suppliers"
            odtrAboutVBDataReader = .ExecuteReader()
        End With
        'StrSupCode(I) = odtrAboutVBDataReader.Item("AccountCode")
        'StrName(I) = odtrAboutVBDataReader.Item("SupplierName")

        With Form3.ListBox1
            .Items.Clear()
            .BeginUpdate()
            Do While odtrAboutVBDataReader.Read
                .Items.Add(odtrAboutVBDataReader.Item("AccountCode ") & " " & odtrAboutVBDataReader.Item("Suppliername"))
                I += 1
            Loop
            .EndUpdate()
        End With
        odtrAboutVBDataReader.Close()
        ocmdAboutVBCommand.Connection.Close()
    End Sub


 
Old May 16th, 2007, 05:23 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Look into the ExecuteNonQuery() method of the oleDbCommand Class; this should give you the information you need to write the data back to the table.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
convert C++ syntax to VB .NET hendyhanusin VB.NET 2002/2003 Basics 0 July 19th, 2007 09:52 PM
What is the Equivalent Syntax in VB.NET r_taduri VB.NET 2002/2003 Basics 1 June 2nd, 2006 12:49 PM
syntax for storing chr(0) in sql server through vb neeraj.khattar Beginning VB 6 1 January 10th, 2005 02:20 PM
Noob needs help with XSL syntax question lancia12 XSLT 1 October 1st, 2004 08:45 AM
Syntax Help - Convert C# to VB.NET ank2go ASP.NET 1.0 and 1.1 Professional 3 July 7th, 2004 09:33 PM





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