473,387 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Easy one I guess... ADO.Net & Access

BY
Hi,

This is my code and it works fine...

Dim Conn As OleDb.OleDbConnection
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Dim i As Integer

Conn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=C:\SAMPLES\Northwind.mdb;Persist Security Info=False")
Cmd = New OleDb.OleDbCommand("SELECT CompanyName FROM CUSTOMERS", Conn)
Conn.Open()

Try
Reader = Cmd.ExecuteReader
i = 1
While (Reader.Read())
ListBox1.Items.Add(i & " " & Reader.GetString(0))
i = i + 1
End While
Finally
Reader.Close()
Conn.Close()
End Try

I have got 2 problems actually where I couldn't find any explanation for in
"Microsoft Visual Basic. Net Step by Step Deluxe Learning Edition"... But I
am still learning...

The first thing is, when someone clicks to a CompanyName in the ListBox(see
code above) I want to display additional information about that company on a
label...

My second problem is, I have another database with contacts... I have a
TextBox, a Button and again a label... If I write the name of a person in
the TextBox and clicks the Button the program should find that person in the
database and show all adress details on the label...

I know that both are related, but I really couldn't find anything about it
on the internet... I have read that the recordsets/records/fields are
changed into .Item, but I couldn't find any detailed information about it,
just as I couldn't find any information about GetString (see code above...?)

I am not expecting that you solve my problems, but I hope that you can point
me in the right direction...:)

Thanks in advance for all your help.

Regards,

BY
Nov 20 '05 #1
3 1162
Hi BY,

Re your first question, a listbox has a selectedindexchanged event; you can
assign a value to the text property of the label there:
label1.text = "ok just clicked " & listbox1.selecteditem

Re your second question, you should set up a dataview to allow you to search
the table for the value you need. I'd strongly recommend you purchase ADO
..Net by David Sceppa - it's one of the best on finding values in a
datatable, whether MS Access or Sql Server. This isn't really that
difficult; if you don't have time for the book and want some sample code,
let me know - I'll put something together for you.

HTH,

Bernie Yaeger

"BY" <no****@hotmail.com> wrote in message
news:BY********************@phobos.telenet-ops.be...
Hi,

This is my code and it works fine...

Dim Conn As OleDb.OleDbConnection
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Dim i As Integer

Conn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=C:\SAMPLES\Northwind.mdb;Persist Security Info=False")
Cmd = New OleDb.OleDbCommand("SELECT CompanyName FROM CUSTOMERS", Conn)
Conn.Open()

Try
Reader = Cmd.ExecuteReader
i = 1
While (Reader.Read())
ListBox1.Items.Add(i & " " & Reader.GetString(0))
i = i + 1
End While
Finally
Reader.Close()
Conn.Close()
End Try

I have got 2 problems actually where I couldn't find any explanation for in "Microsoft Visual Basic. Net Step by Step Deluxe Learning Edition"... But I am still learning...

The first thing is, when someone clicks to a CompanyName in the ListBox(see code above) I want to display additional information about that company on a label...

My second problem is, I have another database with contacts... I have a
TextBox, a Button and again a label... If I write the name of a person in
the TextBox and clicks the Button the program should find that person in the database and show all adress details on the label...

I know that both are related, but I really couldn't find anything about it
on the internet... I have read that the recordsets/records/fields are
changed into .Item, but I couldn't find any detailed information about it, just as I couldn't find any information about GetString (see code above...?)
I am not expecting that you solve my problems, but I hope that you can point me in the right direction...:)

Thanks in advance for all your help.

Regards,

BY

Nov 20 '05 #2
Cor
Hi By,

What you are doing is very nice and compact very usable for the internet
also.

You have enough in your code to do this while I write it in pseudo, while I
follow your approach although I myself would do it on another way.

The next thing you have to do is to construct a new select from your listbox
with the selecteditem and read the information you want to display.

You should do that in a event like "SelectedIndexChanged" (that is
automaticly made when you push on the listbox on your IDE) or as Jan stated
in this newsgroup yesterday " SelectionChangeCommitted" that you has to
choise in your Ide at the top.
(The problem with the selectedIndexChanged is that it fires when it is
loaded, so you have to stop that with a switch and Jan said he had beter
results with SelectionChangeCommitted).

In that event you make a select string as
dim sqlString = _
"SELECT CompanyName, CompanyAdres, etc FROM CUSTOMERS WHERE CompanyName =
'" & _
listbox1.selectedItem.tostring & "'"

Then you can use your reader again to get the information.

I hope that this helps a little bit so far,

Cor
This is my code and it works fine...

Dim Conn As OleDb.OleDbConnection
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Dim i As Integer

Conn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=C:\SAMPLES\Northwind.mdb;Persist Security Info=False")
Cmd = New OleDb.OleDbCommand("SELECT CompanyName FROM CUSTOMERS", Conn)
Conn.Open()

Try
Reader = Cmd.ExecuteReader
i = 1
While (Reader.Read())
ListBox1.Items.Add(i & " " & Reader.GetString(0))
i = i + 1
End While
Finally
Reader.Close()
Conn.Close()
End Try

I have got 2 problems actually where I couldn't find any explanation for in "Microsoft Visual Basic. Net Step by Step Deluxe Learning Edition"... But I am still learning...

The first thing is, when someone clicks to a CompanyName in the ListBox(see code above) I want to display additional information about that company on a label...

My second problem is, I have another database with contacts... I have a
TextBox, a Button and again a label... If I write the name of a person in
the TextBox and clicks the Button the program should find that person in the database and show all adress details on the label...

I know that both are related, but I really couldn't find anything about it
on the internet... I have read that the recordsets/records/fields are
changed into .Item, but I couldn't find any detailed information about it, just as I couldn't find any information about GetString (see code above...?)
I am not expecting that you solve my problems, but I hope that you can point me in the right direction...:)

Thanks in advance for all your help.

Regards,

BY

Nov 20 '05 #3
>-----Original Message-----
Hi,

This is my code and it works fine...

Dim Conn As OleDb.OleDbConnection
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Dim i As Integer

Conn = New OleDb.OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\SAMPLES\Northwind.mdb;Persist Security Info=False")Cmd = New OleDb.OleDbCommand("SELECT CompanyName FROM CUSTOMERS", Conn)Conn.Open()

Try
Reader = Cmd.ExecuteReader
i = 1
While (Reader.Read())
ListBox1.Items.Add(i & " " & Reader.GetString(0))
i = i + 1
End While
Finally
Reader.Close()
Conn.Close()
End Try

I have got 2 problems actually where I couldn't find any explanation for in"Microsoft Visual Basic. Net Step by Step Deluxe Learning Edition"... But Iam still learning...

The first thing is, when someone clicks to a CompanyName in the ListBox(seecode above) I want to display additional information about that company on alabel...
REPLY TO 1:
On the event SelectedIndexChanged
Define the CompanyName
Define the CompanyCode

Label1 as Label = ""
ListBox1.DataTextField = "CompanyName"
ListBox1.DataValueField = "CompanyCode"

Once the user clicked the CompanyName on your listbox
Pass the value to your label control.

Label1.Text = ListBox.SelectedItem.Value
No need to create another connection string, But if you
need to display on your label moer than one field on more
than one Label then you have to do some connection again.
My second problem is, I have another database with contacts... I have aTextBox, a Button and again a label... If I write the name of a person inthe TextBox and clicks the Button the program should find that person in thedatabase and show all adress details on the label...
REPLY 2: The same with the rest...
I know that both are related, but I really couldn't find anything about iton the internet... I have read that the recordsets/records/fields arechanged into .Item, but I couldn't find any detailed information about it,just as I couldn't find any information about GetString (see code above...?)
I am not expecting that you solve my problems, but I hope that you can pointme in the right direction...:)

Thanks in advance for all your help.

Regards,

BY
.

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
14
by: CJM | last post by:
I have a query which produces different results in the Access query builder and in an ASP page (via ADO) An example of the query is: ----------------------------------------------------------...
2
by: lobrys | last post by:
hi I build a VB .NET application that makes file access, environnemet acess, database access, etc.... If I ran the app locally, everything works....(normal) If I copy the app on a server, and...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
14
by: google | last post by:
I am creating a new database for use within our company, that I'd like to make reasonably secure (short of a true server based solution). The back-end of a non-server based database seems to be...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
3
by: codeman | last post by:
Hi all Lets say we have two tables: Customer: Customer_number : Decimal(15) Name : Char(30) Purchase: Purchase_number : Decimal(15)
14
by: EJ | last post by:
I'm real new to javasscript. The task is to develop a web page which will allow users to customize a laptop ... show the price as they change options ... transfer the price and system description...
3
by: gg | last post by:
I specify the Url element as <xsd:element name="Url"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="512"/> <xsd:pattern value="http://+"/> </xsd:restriction>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.