Results 1 to 11 of 11

Thread: Database Error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73

    Database Error

    Can Anyone help me with this problem. I have been trying to connect my vb.net project to a sql database for two weeks. Thanks

    Option Explicit On

    Imports System.data.sqlclient
    Imports System.Data

    Public Class frmMain

    Inherits System.Windows.Forms.Form

    Dim cn As New SqlConnection
    Dim mycommand As New SqlCommand
    Dim myDS As DataSet = New DataSet
    Dim Mydatagrid As New DataGrid
    Dim da As New SqlDataAdapter
    Dim cmdtext As String = "select itemnumber from auto"


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

    cn.ConnectionString = "integrated security=true;initial catalog=justin"

    'cn.Open() ****this gave me an error so I commented it out****

    Dim cmdtext As String = "select * from [auto]"
    Dim da As New SqlDataAdapter
    da.SelectCommand = New SqlCommand(cmdtext, cn)

    Dim dt As New DataTable("Table Auto")
    da.Fill(dt)*****this is highlighted green and says:an unhandled exception of type "system.data.sqlclient.sqlexeption' occured in system.data.dll**********************


    With cboItemNumber
    .DataSource = dt
    .DisplayMember = "ItemNumber"
    End With

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    You call da.Fill on a dataset, not a data table.
    VB Code:
    1. da.Fill(MyDS, "auto)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    Still getting the same error. I am will to pay someone for information that gets this running!!!
    Last edited by pea33nut; Jun 17th, 2004 at 09:39 AM.

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Put the code in a try/catch block to catch the exception message. You set the cmdText twice, once you don't bracket auto, once you don't. I know you bracket keywords in Access if you use them for table or field names, but don't know about SQL Server.

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    You are not specifying the location of the SQL database.

    Your connection should look something like this:

    VB Code:
    1. Dim oSQLConn As SqlConnection = New SqlConnection()
    2. oSQLConn.ConnectionString = "Data Source=(local);" & _
    3.                             "Initial Catalog=myDatabaseName;" & _
    4.                             "Integrated Security=SSPI"
    5. oSQLConn.Open()

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    I have been on here for a week now. It can't be done. I get an error on the SQLConn.Open() now. Anyone know why.

    Dim mycommand As New SqlCommand
    Dim myDS As DataSet = New DataSet
    Dim Mydatagrid As New DataGrid
    Dim da As New SqlDataAdapter

    Dim SQLConn As SqlConnection = New SqlConnection
    SQLConn.ConnectionString = "Data Source=(local);" & _
    "Initial Catalog=JNASI.Justin.dbo;" & _
    "Integrated Security=SSPI"
    SQLConn.Open()



    Dim cmdtext As String = "select * from [auto]"

    da.SelectCommand = New SqlCommand(cmdtext, SQLConn)

    Dim dt As New DataTable("Auto")
    da.Fill(myDS)
    With cboItemNumber
    .DataSource = dt
    .DisplayMember = "ItemNumber"
    End With
    Last edited by pea33nut; Jun 17th, 2004 at 10:13 AM.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Is this the name of your database? "JNASI.Justin.dbo" are you fully qualifying it, or does it really have the periods in it?

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    My program runs but thier is not data in my combo box!!!!


  9. #9
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Forget the datatable code. The da.Fill needs the table name as well. See my earlier post. Set the combobox datasource to the table in the dataset.
    VB Code:
    1. da.Fill(myDS, "Auto")
    2. With cboItemNumber
    3.    .DataSource = myDS.Tables("Auto")
    4.    .DisplayMember = "ItemNumber
    5. End With

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73

    Thanks salvelinus

    YES---------

    You are the man salvelinus!!!!!!!!!!
    Thank you very very much.

  11. #11
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    No problem. Just don't ask for my help with multidimension arrays

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