Results 1 to 2 of 2

Thread: Connection, dataadapter, dataset all set in code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    93

    Connection, dataadapter, dataset all set in code

    I'm trying to set everything in code for this application. Here's the code so far:

    Imports System.Configuration
    Imports System.Collections.Specialized
    Imports System.Data.SqlClient
    Imports System.Threading

    Module ModSubMain

    Public cnnCushions As SqlConnection = New SqlConnection()

    Sub Main()

    Dim sAttr As String
    sAttr = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")

    cnnCushions.ConnectionString = sAttr
    cnnCushions.Open()

    'Dim sAll As NameValueCollection
    'sAll = ConfigurationSettings.AppSettings()

    Application.Run(New frmMain())


    End Sub

    End Module




    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.Hide()
    Dim frm As Splash = New Splash()
    frm.ShowDialog(Me)


    Dim cmCushions As New SqlCommand("CusType", cnnCushions)
    Dim daCushions As New SqlDataAdapter(cmCushions)
    Dim dsCushions As New DataSet()
    Dim drCushions As DataRow

    'fill DataSet
    daCushions.Fill(dsCushions, "Type") ******

    'adding items with DataRow from DataSet
    For Each drCushions In dsCushions.Tables("Type").Rows
    cboType.Items.Add(drCushions("Type"))
    Next
    End Sub

    I want to make the connection to the database in the module and the references to the dataadapter & dataset in the form. When I run through this code I receive an error on the line ending with ******

    Error msg:

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

    Additional information: System error.

    Can anyone tell me where I've gone wrong?

    Thanks,
    Corinne

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You have "CusType" as your SQL statement, which is not valid. If that is a stored procedure name then try setting the SQLCommand.CommandType to stored procedure before using it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width