|
-
Dec 30th, 2011, 06:23 PM
#1
Thread Starter
Frenzied Member
Combo and access 2000 help
Hey Guys,
I was wondering if you could help me out please.
What i'm trying to do is load my information from my access 2000 database the table is called Product and the field is called DVDs what i want it to do is load the DVD's in to the combobox its called cboProduct and when they select a dvd it shows the cost in txtCost on my form this is my connection module code?.
code Code:
Imports System.Data.OleDb
Module modConnect
Public myConn As New OleDbConnection
Public myCmd As New OleDbCommand
Public MyDR As OleDbDataReader
Public frUpdate As Boolean 'Holding for updating entry
Public frView As Boolean 'Holding for viewing entry
Public Function IsConnected(ByVal strQry As String, ByVal ver As Boolean)
Try
If myConn.State = ConnectionState.Open Then myConn.Close()
myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\db1.mrk;User Id=admin;Jet OLEDB:Database Password=test"
myConn.Open()
myCmd.CommandText = strQry
myCmd.Connection = myConn
If ver = False Then
MyDR = myCmd.ExecuteReader()
Else
myCmd.ExecuteNonQuery()
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
End Function
End Module
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Dec 30th, 2011, 09:04 PM
#2
Re: Combo and access 2000 help
Simply populate a DataTable and bind it to both controls:
vb.net Code:
With myComboBox .DisplayMember = "Name" .ValueMember = "ID" .DataSource = myDataTable End With myTextBox.DataBindings.Add("Text", myDataTable, "Cost")
-
Dec 31st, 2011, 06:31 AM
#3
Thread Starter
Frenzied Member
Re: Combo and access 2000 help
Hello,
I've tried this code you gave me but it seems to not work but it also dosent reveal any errors?. This is my full frmorders page code. The code you gave me is under form_load.
Hope you can help please?.
frmOrder Code:
Imports System.Data.OleDb
Public Class frmOrder
Private Sub ButtonCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCancel.Click
Me.Dispose()
End Sub
Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
If frUpdate = False Then
IsConnected("Insert into tblCustomers values(" & _
Me.txtId.Text & ",'" & _
Me.txtName.Text & "','" & _
Me.txtAddress.Text & "','" & _
Me.txtNotes.Text & "','" & _
Me.DateGot.Text & "','" & _
Me.PayDate.Text & "','" & _
Me.cboOrder.Text & "','" & _
Me.txtCost.Text & "')", True)
MsgBox("Successfully Saved!", MsgBoxStyle.Information, "Saved")
Call LoadID()
Else
IsConnected("Update tblCustomers set FullName='" & Me.txtName.Text & _
"',Address='" & Me.txtAddress.Text & _
"',Notes='" & Me.txtNotes.Text & _
"',DateGot='" & Me.DateGot.Text & _
"',PayDate='" & Me.PayDate.Text & _
"',Stuff='" & Me.cboOrder.Text & _
"',Cost='" & Me.txtCost.Text & "' where ID='" & Me.txtId.Text & "'", True)
MsgBox("Successfully Updated!", MsgBoxStyle.Information, "Updated")
End If
End Sub
Private Sub frmOrder_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
frUpdate = False
Me.Dispose()
End Sub
Private Sub frmOrder_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
On Error GoTo err
Call LoadID()
Exit Sub
err:
MsgBox(Err.Description, MsgBoxStyle.Critical, "Error")
With cboOrder
.DisplayMember = "FullName"
.ValueMember = "ID"
.DataSource = "tblCustomers"
End With
txtCost.DataBindings.Add("Text", "tblCustomers", "Cost")
End Sub
Private Sub LoadID()
If frUpdate = False Then
txtName.Text = ""
txtAddress.Text = ""
txtNotes.Text = ""
DateGot.Text = ""
PayDate.Text = ""
cboOrder.Text = ""
txtCost.Text = ""
IsConnected("Select count(ID) from tblCustomers", False)
If MyDR.Read = True Then
Me.txtId.Text = MyDR.GetValue(0) + 1
Else
Me.txtId.Text = 1
End If
txtName.Focus()
End If
End Sub
End Class
Last edited by Jamie_Garland; Dec 31st, 2011 at 07:14 AM.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Dec 31st, 2011, 10:05 AM
#4
Re: Combo and access 2000 help
The code I provided works fine. You just didn't implement it properly in your own app. Have a close look at what I did and compare it to what you did. There's a big glaring difference.
-
Dec 31st, 2011, 10:25 AM
#5
Thread Starter
Frenzied Member
Re: Combo and access 2000 help
This is what u did
Code Code:
With myComboBox
* * .DisplayMember = "Name"
* * .ValueMember = "ID"
* * .DataSource = myDataTable
End With
*
myTextBox.DataBindings.Add("Text", myDataTable, "Cost")
And what I did I had to do as it was give things like not defined and that.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Dec 31st, 2011, 11:13 AM
#6
Re: Combo and access 2000 help
What do you think this does?
Code:
With myComboBox
.DisplayMember = "Name"
.ValueMember = "ID"
.DataSource = myDataTable
End With
myTextBox.DataBindings.Add("Text", myDataTable, "Cost")
Doesn't that look like I'm assigning a DataTable to the DataSource property? What are you assigning to your DataSource property? Is it your DataTable?
-
Dec 31st, 2011, 11:31 AM
#7
Thread Starter
Frenzied Member
Re: Combo and access 2000 help
I did it like this?
Code Code:
With cboOrder
.DisplayMember = "FullName"
.ValueMember = "ID"
.DataSource = "tblcustomers"
End With
*
Txtcost.DataBindings.Add("Text", tblCustomers, "Cost")
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Dec 31st, 2011, 11:33 AM
#8
Thread Starter
Frenzied Member
Re: Combo and access 2000 help
I did it like this?
Code Code:
With cboOrder
.DisplayMember = "FullName"
.ValueMember = "ID"
.DataSource = "tblcustomers"
End With
*
Txtcost.DataBindings.Add("Text", tblCustomers, "Cost")[/QUOTE]
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Dec 31st, 2011, 12:08 PM
#9
Re: Combo and access 2000 help
Instead of just reposting code that you have already posted and therefore has no value at all, how about you answer my question?
What are you assigning to your DataSource property? Is it your DataTable?
-
Dec 31st, 2011, 12:22 PM
#10
Thread Starter
Frenzied Member
Re: Combo and access 2000 help
Yeah it's my DataTable from the database I'm using.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Dec 31st, 2011, 12:47 PM
#11
Re: Combo and access 2000 help
No, it's not your DataTable. It's a String. What do double quotes mean in VB.NET? When have you ever used a variable inside double quotes?
-
Dec 31st, 2011, 12:50 PM
#12
Thread Starter
Frenzied Member
Re: Combo and access 2000 help
i'm not sure thats the way i have been showing for awhile on tutorials?
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Dec 31st, 2011, 12:56 PM
#13
Re: Combo and access 2000 help
I very much doubt that. Even if it was, surely you know the difference between a String containing he name of a DataTable and the DataTable itself.
-
Dec 31st, 2011, 01:09 PM
#14
Thread Starter
Frenzied Member
Re: Combo and access 2000 help
nope i dont im new to this and learning from tutorials?.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Dec 31st, 2011, 02:57 PM
#15
Thread Starter
Frenzied Member
Re: Combo and access 2000 help
Do i have to put this at the top of the form.
also just tried this but still dosent work?. Its also loading from a diffrent table aswell the original table is called tblCustomers but this is tblStuff.?
vb Code:
Dim tblStuff as string With cboOrder .DisplayMember = "NameName" .ValueMember = "ID" .DataSource = tblStuff End With txtCost.DataBindings.Add("Name", tblStuff, "Cost")
?.
Last edited by Jamie_Garland; Dec 31st, 2011 at 04:16 PM.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Dec 31st, 2011, 11:07 PM
#16
Re: Combo and access 2000 help
You need to put the code wherever you want it to be executed. If you want it to be executed when the user clicks a Button then you put it in the Click event handler of that Button. If you want it to be executed when a form loads then you put it in Load event handler of that form. It's up to you to decide when you want the code executed and then handle the appropriate event.
As for the code not working, that's because you haven't done it properly. Have you actually read the documentation for the members that you're using? If not, why not? Do you know what each of the parameters of the Add method mean? If not, why haven't you read the documentation to find out?
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
|