D
dennist
I have a bizarre error I can't figure out. If I open a
connection in a subroutine, it returns as error: Here is
the subroutine.
Friend Sub NewTopic() 'As Boolean
'Return False
Dim cn As New OleDbConnection(gstrConn)
cn.Open()
Dim cmd As New OleDbCommand("SELECT * FROM
Topics", cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
'dim tblTopics as ds
da.Fill(ds, "Topics")
'Return True
cn.Close()
End Sub
An unhandled exception of
type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll
However, if I change it to a function, everything else
the same except for return values, it works fine:
Friend Function NewTopic() As Boolean
Return False
Dim cn As New OleDbConnection(gstrConn)
cn.Open()
Dim cmd As New OleDbCommand("SELECT * FROM
Topics", cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
'dim tblTopics as ds
da.Fill(ds, "Topics")
Return True
cn.Close()
End Function
Now this isn't generally true in my program. I call an
overloaded subroutine to fill listboxes or comboboxes and
it works fine. Here is the form load event from which I
call the call the class subroutine.
Private Sub frmtopicfromstart_Load(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim clsDChor As New clsDataChor
txtTextGeneral.Text = ""
clsDChor.FillBox(cboTopicIssuers, "SELECT
TopicIssuers.ID, TopicIssuers.Issuer FROM TopicIssuers
ORDER BY TopicIssuers.Issuer;", "TopicIssuers")
clsDChor.FillBox(cboPublications, "SELECT
Publications.ID, Publications.Publication FROM
Publications ORDER BY
Publications.Publication;", "Publications")
clsDChor.FillBox(cboPOV, "SELECT PointsOfView.ID,
PointsOfView.PointOfView FROM PointsOfView ORDER BY
PointsOfView.PointOfView;", "PointsOfView")
clsDChor.FillBox(cboDateType, "SELECT
DateType.ID, DateType.DateType FROM DateType ORDER BY
DateType.DateType;", "DateType")
'Dim strDate As String = "05/22/2003"
'If IsDate(strDate) Then
' dtp1.Value = strDate
'End If
End Sub
and here is the overloaded subroutine, which works
fine:
Overloads Sub FillBox(ByRef lst As ListBox, ByVal
strSQL As String, ByVal tbl As String)
Dim cn As New OleDbConnection(gstrConn)
cn.Open()
Dim cmd As New OleDbCommand(strSQL, cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
da.Fill(ds, tbl)
Dim tbl1 As DataTable = ds.Tables(0)
Dim row As DataRow = tbl1.Rows(0)
' Bind the DataSet to the DataList
lst.ValueMember = ds.Tables(tbl).Columns
(0).ColumnName
lst.DisplayMember = ds.Tables(tbl).Columns
(1).ColumnName
lst.DataSource = ds.Tables(tbl)
cn.Close()
End Sub
Overloads Sub FillBox(ByRef lst As ComboBox, ByVal
strSQL As String, ByVal tbl As String)
Dim cn As New OleDbConnection(gstrConn)
cn.Open()
Dim cmd As New OleDbCommand(strSQL, cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
da.Fill(ds, tbl)
' Bind the DataSet to the DataList
lst.ValueMember = ds.Tables(tbl).Columns
(0).ColumnName
lst.DisplayMember = ds.Tables(tbl).Columns
(1).ColumnName
lst.DataSource = ds.Tables(tbl)
cn.Close()
End Sub
I've wasted a lot of time trying to figure this one
out. I hope one of you have an idea.
thanks.
dennist
connection in a subroutine, it returns as error: Here is
the subroutine.
Friend Sub NewTopic() 'As Boolean
'Return False
Dim cn As New OleDbConnection(gstrConn)
cn.Open()
Dim cmd As New OleDbCommand("SELECT * FROM
Topics", cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
'dim tblTopics as ds
da.Fill(ds, "Topics")
'Return True
cn.Close()
End Sub
An unhandled exception of
type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll
However, if I change it to a function, everything else
the same except for return values, it works fine:
Friend Function NewTopic() As Boolean
Return False
Dim cn As New OleDbConnection(gstrConn)
cn.Open()
Dim cmd As New OleDbCommand("SELECT * FROM
Topics", cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
'dim tblTopics as ds
da.Fill(ds, "Topics")
Return True
cn.Close()
End Function
Now this isn't generally true in my program. I call an
overloaded subroutine to fill listboxes or comboboxes and
it works fine. Here is the form load event from which I
call the call the class subroutine.
Private Sub frmtopicfromstart_Load(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim clsDChor As New clsDataChor
txtTextGeneral.Text = ""
clsDChor.FillBox(cboTopicIssuers, "SELECT
TopicIssuers.ID, TopicIssuers.Issuer FROM TopicIssuers
ORDER BY TopicIssuers.Issuer;", "TopicIssuers")
clsDChor.FillBox(cboPublications, "SELECT
Publications.ID, Publications.Publication FROM
Publications ORDER BY
Publications.Publication;", "Publications")
clsDChor.FillBox(cboPOV, "SELECT PointsOfView.ID,
PointsOfView.PointOfView FROM PointsOfView ORDER BY
PointsOfView.PointOfView;", "PointsOfView")
clsDChor.FillBox(cboDateType, "SELECT
DateType.ID, DateType.DateType FROM DateType ORDER BY
DateType.DateType;", "DateType")
'Dim strDate As String = "05/22/2003"
'If IsDate(strDate) Then
' dtp1.Value = strDate
'End If
End Sub
and here is the overloaded subroutine, which works
fine:
Overloads Sub FillBox(ByRef lst As ListBox, ByVal
strSQL As String, ByVal tbl As String)
Dim cn As New OleDbConnection(gstrConn)
cn.Open()
Dim cmd As New OleDbCommand(strSQL, cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
da.Fill(ds, tbl)
Dim tbl1 As DataTable = ds.Tables(0)
Dim row As DataRow = tbl1.Rows(0)
' Bind the DataSet to the DataList
lst.ValueMember = ds.Tables(tbl).Columns
(0).ColumnName
lst.DisplayMember = ds.Tables(tbl).Columns
(1).ColumnName
lst.DataSource = ds.Tables(tbl)
cn.Close()
End Sub
Overloads Sub FillBox(ByRef lst As ComboBox, ByVal
strSQL As String, ByVal tbl As String)
Dim cn As New OleDbConnection(gstrConn)
cn.Open()
Dim cmd As New OleDbCommand(strSQL, cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
da.Fill(ds, tbl)
' Bind the DataSet to the DataList
lst.ValueMember = ds.Tables(tbl).Columns
(0).ColumnName
lst.DisplayMember = ds.Tables(tbl).Columns
(1).ColumnName
lst.DataSource = ds.Tables(tbl)
cn.Close()
End Sub
I've wasted a lot of time trying to figure this one
out. I hope one of you have an idea.
thanks.
dennist