[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Re: Problem opening database

Greg Hicks

11/20/2002 2:10:00 AM

I realized my problem in getting the database to open was in the structure
of my code (mainly where I was declaring some of my holders) and now the
database gets opened, and my ComboBox Items loop occurs and gets the proper
count of hits (from the database SQL statement) but the ComboBox does not
get populated with the list of employee numbers but rather with
System.Data.OleDB.OleDBCommand items for each of the numbered items. In
other words if 60 employees numbers satisfy my query I have 60 instances of
the System.Data information in my combobox. Thanks in advance.
Greg Hicks
"Greg Hicks" <greg.news@ajlb2.com> wrote in message
news:utle3kq1um73f7@corp.supernews.com...
> I have the following code, but my database is never getting opened and I
> can't seem to see why. I am new to database programming in .Net and am
sure
> it is right in my face, but I can't see it. Anyone have a thought? Thanks.
> Greg Hicks
>
> -----------------------------------------------------------------
> timeclok.ini file contains single line with:
> Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\rmkodata.mdb;Persist
> Security Info=False
> -----------------------------------------------------------------
>
> Imports System.Data.OleDb
>
> Public Class fclsTimeclock
> Inherits System.Windows.Forms.Form
>
> 'Dimensioned variable
> Dim data_path As String
> Dim SQLEmpNums As String = "select [Employee Number] from [Employees]
> where [Active] = true order by [Employee Number]"
> Dim conn As OleDbConnection = New OleDbConnection(data_path)
> Dim GetEmpNum As OleDbCommand = New OleDbCommand(SQLEmpNums, conn)
> Dim reader As OleDbDataReader
>
> Private Sub fclsTimeclock_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> On Error Resume Next
> FileOpen(1, "c:\windows\timeclok.ini", OpenMode.Input)
> If Err.Number Then
> MsgBox("Unable to open c:\windows\timeclok.ini")
> Exit Sub
> End If
> Input(1, data_path)
> FileClose(1)
> Call MI_Update_Click()
> btnClockIn.Visible = False
> btnClockOut.Visible = False
> End Sub
>
> Private Sub MI_Update_Click()
> txtDirections.Text = "Enter your employee number"
> btnClockIn.Visible = False
> btnClockOut.Visible = False
> Try
> conn.Open()
> reader = GetEmpNum.ExecuteReader
> Catch ex As Exception
> MsgBox("Error opening database")
> Exit Sub
>
> While reader.Read
> cboEmpNum.Items.Add(reader)
> End While
> Finally
> reader.Close()
> conn.Close()
> End Try
>
> End Sub
> End Class
>
>
>


1 Answer

Greg Hicks

11/20/2002 8:50:00 PM

0

OK, I got the last problem worked out and figured out the proper line to
fill my combobox, instead of the cboEmpNum.Items.Add(GetEmpNum) line I
instead used - cboEmpNum.Items.Add(reader.Item("Employee Number") and now I
am filling properly. Now the next question I have is getting the Employee
name from the database based on the number selected from the combobox. I
have created a call to a new procedure (in_or_out) with the following code:

Private Sub In_or_out()
Dim SQLEmpName As String = "select [Last Name], [First Name] from
[Employees] where [Employees Number] =" & cboEmpNum.Text
Dim SQLInorOut As String = "select * from [Clock In] where [Employee
Number] =" & cboEmpNum.Text
Dim conn As OleDbConnection = New OleDbConnection(data_path)
Dim GetEmpName As OleDbCommand = New OleDbCommand(SQLEmpName, conn)
Dim GetInorOut As OleDbCommand = New OleDbCommand(SQLInorOut, conn)

If cboEmpNum.Text <> "" Then
'get name corresponding to employee number selected
Try
conn.Open()
lblEmpName.Text = GetEmpName.co

Catch ex As Exception
MsgBox("Error getting employee's name from database")
Exit Sub
Finally
conn.Close()

End Try

End If
End Sub

But now I can't figure out what code to use on the lblEmpName.Text = line to
select the name from the database based on employee number.
Thanks for all the help so far and I am really starting to get this, mostly
due to all of your patience!
Greg Hicks
"Greg Hicks" <greg.news@ajlb2.com> wrote in message
news:utlo8rni10gtae@corp.supernews.com...
> I realized my problem in getting the database to open was in the structure
> of my code (mainly where I was declaring some of my holders) and now the
> database gets opened, and my ComboBox Items loop occurs and gets the
proper
> count of hits (from the database SQL statement) but the ComboBox does not
> get populated with the list of employee numbers but rather with
> System.Data.OleDB.OleDBCommand items for each of the numbered items. In
> other words if 60 employees numbers satisfy my query I have 60 instances
of
> the System.Data information in my combobox. Thanks in advance.
> Greg Hicks
> "Greg Hicks" <greg.news@ajlb2.com> wrote in message
> news:utle3kq1um73f7@corp.supernews.com...
> > I have the following code, but my database is never getting opened and I
> > can't seem to see why. I am new to database programming in .Net and am
> sure
> > it is right in my face, but I can't see it. Anyone have a thought?
Thanks.
> > Greg Hicks
> >
> > -----------------------------------------------------------------
> > timeclok.ini file contains single line with:
> > Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Temp\rmkodata.mdb;Persist
> > Security Info=False
> > -----------------------------------------------------------------
> >
> > Imports System.Data.OleDb
> >
> > Public Class fclsTimeclock
> > Inherits System.Windows.Forms.Form
> >
> > 'Dimensioned variable
> > Dim data_path As String
> > Dim SQLEmpNums As String = "select [Employee Number] from
[Employees]
> > where [Active] = true order by [Employee Number]"
> > Dim conn As OleDbConnection = New OleDbConnection(data_path)
> > Dim GetEmpNum As OleDbCommand = New OleDbCommand(SQLEmpNums, conn)
> > Dim reader As OleDbDataReader
> >
> > Private Sub fclsTimeclock_Load(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> > On Error Resume Next
> > FileOpen(1, "c:\windows\timeclok.ini", OpenMode.Input)
> > If Err.Number Then
> > MsgBox("Unable to open c:\windows\timeclok.ini")
> > Exit Sub
> > End If
> > Input(1, data_path)
> > FileClose(1)
> > Call MI_Update_Click()
> > btnClockIn.Visible = False
> > btnClockOut.Visible = False
> > End Sub
> >
> > Private Sub MI_Update_Click()
> > txtDirections.Text = "Enter your employee number"
> > btnClockIn.Visible = False
> > btnClockOut.Visible = False
> > Try
> > conn.Open()
> > reader = GetEmpNum.ExecuteReader
> > Catch ex As Exception
> > MsgBox("Error opening database")
> > Exit Sub
> >
> > While reader.Read
> > cboEmpNum.Items.Add(reader)
> > End While
> > Finally
> > reader.Close()
> > conn.Close()
> > End Try
> >
> > End Sub
> > End Class
> >
> >
> >
>
>