Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 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
  #1 (permalink)  
Old August 12th, 2005, 09:59 PM
Registered User
 
Join Date: Aug 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql error with vb.net

hello i am working on the project in chapter 16 page 638 of the book Beginning VB.NET 2nd edition, and i am getting this error:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.


the line...

myConnection.Open

is highlighted.

i'm trying to connect to the sql server on a box running win 2000 server and i'm running vb.net on a win xp box. the wierd thing is that i can navigate to the database through my network places (so i do have connectivity), but i can't get to it through vb.net.

here's my code...



'Import Data and SqlClient namespaces...
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim myConnection As SqlConnection = New _
        SqlConnection("server=(\\G5-media-server\SQLServer 2000\MSSQL\Data);database=pubs;uid=administrator;p wd=")

    Dim myDataAdapter As New SqlDataAdapter
    Dim myDataSet As DataSet = New DataSet

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents grdAuthorTitles As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.grdAuthorTitles = New System.Windows.Forms.DataGrid
        CType(Me.grdAuthorTitles, System.ComponentModel.ISupportInitialize).BeginIni t()
        Me.SuspendLayout()
        '
        'grdAuthorTitles
        '
        Me.grdAuthorTitles.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.grdAuthorTitles.DataMember = ""
        Me.grdAuthorTitles.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.grdAuthorTitles.Location = New System.Drawing.Point(5, 5)
        Me.grdAuthorTitles.Name = "grdAuthorTitles"
        Me.grdAuthorTitles.Size = New System.Drawing.Size(584, 192)
        Me.grdAuthorTitles.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(592, 196)
        Me.Controls.Add(Me.grdAuthorTitles)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n
        Me.Text = "Bound Dataset"
        CType(Me.grdAuthorTitles, System.ComponentModel.ISupportInitialize).EndInit( )
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Set the SelectCommand properties...
        myDataAdapter.SelectCommand = New SqlCommand
        myDataAdapter.SelectCommand.Connection = myconnection
        myDataAdapter.SelectCommand.CommandText = _
            "SELECT au_lname, au_fname, title, price " & _
            "FROM authors " & _
            "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
            "JOIN titles ON titleauthor.title_id = titles.title_id " & _
            "ORDER by au_lname, au_fname"
        myDataAdapter.SelectCommand.CommandType = CommandType.Text

        'Open the database connection...
        myConnection.Open()

        'Now execute teh command...
        myDataAdapter.SelectCommand.ExecuteNonQuery()

        'Fill the Dataset object with data...
        myDataAdapter.Fill(myDataSet, "authors")

        'Close the database connection...
        myConnection.Close()

        'Set the DataGrid properties to bind it to our data...
        grdAuthorTitles.DataSource = myDataSet
        grdAuthorTitles.DataMember = "authors"

    End Sub

End Class


THANK YOU!!!


  #2 (permalink)  
Old August 14th, 2005, 12:04 AM
Registered User
 
Join Date: Aug 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

NEVERMIND...i found the answer here...this worked for me and hopefully for someone else...THANKS "K"!!!

http://p2p.wrox.com/topic.asp?TOPIC_ID=24349


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 1.1,VB.NET,crystal reports, SQl server gvi Crystal Reports 1 September 11th, 2008 02:55 AM
VB.net and SQL select skicrud VB.NET 1 November 4th, 2004 07:02 AM
ASP.NET Using VB.NET Chapt 3 Code error? uh6uj All Other Wrox Books 1 February 26th, 2004 10:46 AM
MSDE and SQL CE (using VB.NET and ADO.NET) LEGS ADO.NET 0 July 12th, 2003 11:27 AM





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