p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB.NET 2002/2003 Basics (http://p2p.wrox.com/forumdisplay.php?f=76)
-   -   sql error with vb.net (http://p2p.wrox.com/showthread.php?t=32453)

4-elements August 12th, 2005 09:59 PM

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!!!



4-elements August 14th, 2005 12:04 AM

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


All times are GMT -4. The time now is 08:45 AM.

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