Sheffield Forum
VB.NET linkin to microsoft access
Home > General Forums > Computer & Tech Chat

Reply
 
Thread Tools Search this Thread
Old 17-02-2005, 11:41   #1
shelly121
Registered User
 
Join Date: Feb 2005
Location: shropshire,uk
Total Posts: 71
hey ppz! i need sum help- tryn to do a mortage database for an assignment at uni, and this is wot i have at the start of the form code. i "borrowed" it and adapted it for mine, but lesson learnt-it doesnt always work that way!!!
Quote:
CN = New ADODB.Connection()
CN.Provider = "MICROSOFT.JET.OLEDB.4.0" 'ACCESS CONNECTION
CN.Open("C:\Documents and Settings\Kathleen Hughes.KATHLEEN\My Documents\michelle\yr 2004-5\vb.net\ASSIGNMENT\assignmeet2\mortgage.MDB")

RS = New ADODB.Recordset()
RS.Open("select * from MORTGAGE order by mortgagecode", CN, 1, 2)
as when i use the adapter wizard it says there is a problem with the "select *" , any1 know wot iv done wrong, do i need that "RS.open("select......) etc" bit???
__________________
*shelly*
  Reply With Quote
Sponsored Links - Register and/or Login to hide this ad.
Old 17-02-2005, 11:51   #2
JoeP
A Regular Joe
 
JoeP's Avatar
 
Join Date: Feb 2004
Location: Dun Moddin'
Total Posts: 14,721
I'm assuming that there is a table called MORTGAGE in the Mortgage.mdb database, and that it has a field called mortgagecode?

Joe
__________________
"I shall not commit the fashionable stupidity of regarding everything I cannot explain as a fraud." - CG Jung
My homepage : http://www.joepritchard.me.uk
  Reply With Quote
Old 17-02-2005, 11:59   #3
shelly121
Registered User
 
Join Date: Feb 2005
Location: shropshire,uk
Total Posts: 71
Quote:
Originally posted by JoePritchard
I'm assuming that there is a table called MORTGAGE in the Mortgage.mdb database, and that it has a field called mortgagecode?

Joe
ah-ha!thanks 4 that. so iv fixed that and now its come up with a second problem!!!(the part in "quote", is the part it highlights):
CN.Provider = "MICROSOFT.JET.OLEDB.4.0" 'ACCESS CONNECTION
CN.Open("C:\Documents and Settings\Kathleen Hughes.KATHLEEN\My Documents\michelle\yr 2004-5\vb.net\ASSIGNMENT\assignmeet2\mortgage.MDB")

RS = New ADODB.Recordset()
RS.Open("select * from client order by Name", CN, 1, 2)

Quote:
txtFirstName.Text = RS.Fields("Name").Value
txtLastName.Text = RS.Fields("Last Name").Value
txtDOB.Text = RS.Fields("DOB").Value
txtPostcode.Text = RS.Fields("Current Postcode").Value
  Reply With Quote
Old 17-02-2005, 12:10   #4
JoeP
A Regular Joe
 
JoeP's Avatar
 
Join Date: Feb 2004
Location: Dun Moddin'
Total Posts: 14,721
What error message are you getting?

Typically that line might throw an error for a few reasons :

Control (txtFirstName) doesn't exist on the form.
Database field 'name' doesn't exist.
Control isn't visible / enabled.

Joe
__________________
"I shall not commit the fashionable stupidity of regarding everything I cannot explain as a fraud." - CG Jung
My homepage : http://www.joepritchard.me.uk
  Reply With Quote
Old 17-02-2005, 12:30   #5
shelly121
Registered User
 
Join Date: Feb 2005
Location: shropshire,uk
Total Posts: 71
Quote:
Originally posted by JoePritchard
What error message are you getting?

Typically that line might throw an error for a few reasons :

Control (txtFirstName) doesn't exist on the form.
Database field 'name' doesn't exist.
Control isn't visible / enabled.

Joe
when i play/open the form it says:
Quote:
an unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

Additional information: Cast from type 'DBNull' to type 'String' is not valid
??
i know that txtfirstname DOES exist on the form-its a textbox. and im sure its ont he table as a column name?? but i dont understand what you mean by control isnt visible???so could that be it???
__________________
*shelly*

Last edited by shelly121; 17-02-2005 at 12:35.
  Reply With Quote
Old 17-02-2005, 12:36   #6
JoeP
A Regular Joe
 
JoeP's Avatar
 
Join Date: Feb 2004
Location: Dun Moddin'
Total Posts: 14,721
Ahhh.....

the field is empty in the database and VB is trying to force the Null to fit in the text box property.

Try txtName.text = CStr(RS.Fields("Name").Value)

Now, not sure about this 'cos it's a while since I've played with VB.NET!

But teh problem is definitey to do with the fact that it's returning a Null value. Might be that the database is empty? No records in?

If that's the case you would get an error like this. You should be checking whether the recordset has records in it before trying to process them.

And you're lab demonstrators should be doing a better job of teaching you...

Joe
__________________
"I shall not commit the fashionable stupidity of regarding everything I cannot explain as a fraud." - CG Jung
My homepage : http://www.joepritchard.me.uk
  Reply With Quote
Old 17-02-2005, 12:41   #7
shelly121
Registered User
 
Join Date: Feb 2005
Location: shropshire,uk
Total Posts: 71
Quote:
Originally posted by JoePritchard
Ahhh.....

the field is empty in the database and VB is trying to force the Null to fit in the text box property.

Try txtName.text = CStr(RS.Fields("Name").Value)

Now, not sure about this 'cos it's a while since I've played with VB.NET!.......
And you're lab demonstrators should be doing a better job of teaching you...

Joe
that mite just work...will have to change it all- but thanks a lot - u been a gr8 help!
__________________
*shelly*
  Reply With Quote
Old 17-02-2005, 12:54   #8
shelly121
Registered User
 
Join Date: Feb 2005
Location: shropshire,uk
Total Posts: 71
Quote:
Originally posted by shelly121
that mite just work...will have to change it all- but thanks a lot - u been a gr8 help!
yep its workin!! brilliant!! thanks.
__________________
*shelly*
  Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT. The time now is 03:29.
POSTS ON THIS FORUM ARE NOT ACTIVELY MONITORED
Click "Report Post" under any post which may breach our terms of use.
©2002-2012 SheffieldForum.co.uk | Powered by vBulletin ©2013