|
-
Jun 17th, 2004, 08:42 AM
#1
Thread Starter
Lively Member
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
-
Jun 17th, 2004, 08:49 AM
#2
Frenzied Member
You call da.Fill on a dataset, not a data table.
-
Jun 17th, 2004, 09:13 AM
#3
Thread Starter
Lively Member
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.
-
Jun 17th, 2004, 09:38 AM
#4
Frenzied Member
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.
-
Jun 17th, 2004, 09:47 AM
#5
You are not specifying the location of the SQL database.
Your connection should look something like this:
VB Code:
Dim oSQLConn As SqlConnection = New SqlConnection()
oSQLConn.ConnectionString = "Data Source=(local);" & _
"Initial Catalog=myDatabaseName;" & _
"Integrated Security=SSPI"
oSQLConn.Open()
-
Jun 17th, 2004, 10:07 AM
#6
Thread Starter
Lively Member
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.
-
Jun 17th, 2004, 10:29 AM
#7
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
-
Jun 17th, 2004, 10:33 AM
#8
Thread Starter
Lively Member
My program runs but thier is not data in my combo box!!!!
-
Jun 17th, 2004, 10:43 AM
#9
Frenzied Member
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:
da.Fill(myDS, "Auto")
With cboItemNumber
.DataSource = myDS.Tables("Auto")
.DisplayMember = "ItemNumber
End With
-
Jun 17th, 2004, 10:51 AM
#10
Thread Starter
Lively Member
Thanks salvelinus
YES---------
You are the man salvelinus!!!!!!!!!!
Thank you very very much.
-
Jun 17th, 2004, 11:24 AM
#11
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|