Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Result in List Box

Status
Not open for further replies.

SMA00

MIS
May 15, 2005
10
CA
Hi,

I am unable to insert following SQL Statement Result in to List Box. Can some one guide me with code how to do it.

SSQL = Select custid, name, address from Customer

SM


 
How have you been trying to do it so far?

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Hi Harleyquinn,

I have ADODC1 control and DBGrid1 Control.

SQL = Select custid, name, address from Customer

I am unable to display in my result in DBGrid1.

Can you suggest what setup do i need in ADODC1 and DBGrid1 to display record.

Best Regards
SM

 
Hi,

I think, the simple way to do this is next:

1. Open the recordset with some query:

Query = "SELECT BLA,BLA,BLA FROM ENYTABLE"
rsRecordset open, connection,adOpenDinamic, adLockOptimistic, adCmdUnknown

2. you will get in rsRecordset all record from this table. In case, that you will show the recordset in some datagrid, put this code:

Set Datagrid1.DataSource = rsRecordset
Datagrid1.Refresh

3. in other case, when you will put the recordset in list box, I suggest, this routine:

do while not rsRecordset.EOF

listbox.aditem rsRecordset(0) - 0 is number of field in recordset

loop

I hope, this will work

Tnx,DaT
 
I believe topci is German (the comma separation of subordinate clauses as in "I hope, this will work" gives me this idea), and I'm sure his English is much better than my German, so this isn't a criticism. However, there are several misspellings in the code, which will not work as is. (adopendynamic, additem)

Also, he's telling you how to do it without the data control, using an ADO Recordset instead. I prefer this method as well. I don't like the data control and I don't like data binding either, unless I'm not trying to update anything. However, here are the steps to make the Data Control work with the DataGrid Control:

On the ADO Data Control:
1. Set the Connectionstring property to a valid connection of some sort. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;Persist Security Info=False" sets the string to the Northwind Database that ships with Visual Studio 6. will give you numerous examples, too, and you can use the builder to help you as well (just hit the ... by the ConnectionString property in the Data control).

2. Set the RecordSource property to your SQL string. I used "select * from customers".

With the DataGrid control:
1. Set the DataSource property to your ADO Data Control.

That's all there is to it. If you want help using a Recordset instead of a Data Control, post back.

HTH

Bob
 
This may be out to lunch (i.e. complete garbage) but ADODC1 looks like an ADO data control but DBGrid1 is the default name usually assigned to a DAO data grid control. If you are attempting to assign an ADO record source (i.e. ADODB1) to a DBGrid control note that the two are incompatible. You need to use a DataGrid control Microsoft Data Grid Control 6.0 (SP6) (OLEDB)
 
Good heavens, I missed that entirely. I'll bet you're right, too, Golom. I'll look forward to knowing for sure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top