Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 load data to listview control from sql table

Author  Topic 

deekshitulu
Starting Member

8 Posts

Posted - 2012-09-15 : 03:55:10
Sir,

SQL SERVER, 2005
Visual basic 6 as front end.
Database Name: GRANTH3
ODBC data source Name : sai
Table Name: CATS
Number of Field in the Table is :73

I need to load date from the following Fields in the above table CATS to list view control
Required Field: No of Field in 73
DATA_ADDED 29
ACCESSION_NO 57
TITLE 7
PUB_ID1_NAME 61
CLASS_NAME 71

I wrote following code:
 Sub LoadData()
ListView1.ListItems.Clear
Dim list As ListItem
Dim x As Integer
connectdb
rs.Open "SELECT ACCESSION_NO,TITLE,PUB_ID_NAME,CLASS_NO FROM CATS", conn, adOpenStatic, adLockOptimistic
'rs.Open "SELECT TITLE,ACCESSION_NO,DATE_ADDED FROM CATS"
Do Until rs.EOF
Set list = ListView1.ListItems.Add(, , rs(0))
For x = 1 To 3
list.SubItems(x) = rs(x)
Next x
rs.MoveNext
Loop
Set rs = Nothing
'db.Close: Set db = Nothing
End Sub

But it is giving an error 94 ‘in valid use of null

And high lighting the following line of code
list.SubItems(x) = rs(x)

is there any possibility to copy and paste the table and rename the table and delete the not required fields so that I execute the string "rs.open"Select * from CATS), conn,3,3"

ch.s.deekshitulu

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-15 : 22:04:40
you can do SELECT <your required columns alone> INTO NewTable FROM CATS

Then do rename of table to what you want using

EXEC sp_rename 'NewTable', 'your new name'

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

deekshitulu
Starting Member

8 Posts

Posted - 2012-09-16 : 02:42:29
Sir,
Where I have to put this line of code ie.,
SELECT <your required columns alone> INTO NewTable FROM CATS
in my above code (after which line of code?)
Thanks in advance

ch.s.deekshitulu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-16 : 12:17:42
quote:
Originally posted by deekshitulu

Sir,
Where I have to put this line of code ie.,
SELECT <your required columns alone> INTO NewTable FROM CATS
in my above code (after which line of code?)
Thanks in advance

ch.s.deekshitulu



the place where you've to create a new table with columns you need to use the above statement


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

deekshitulu
Starting Member

8 Posts

Posted - 2012-09-16 : 18:31:56
Sir,
can i write above statemnt like below:
rs.MoveNext
Loop
rs.Open"SELECT ACCESSION_NO,TITLE,PUB_ID_NAME,CLASS_NO INTO NewTable FROM CATS",conn,adOpenStatic, adLockOptimistic
Set rs = Nothing

by expending the table, I see a sub list like below:
database diagrams
Tables
views
synonyms
programability
security


can i attach view of a table to listview control like a table attached to listview control

Thanks in advance



ch.s.deekshitulu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-16 : 22:42:30
quote:
Originally posted by deekshitulu

Sir,
can i write above statemnt like below:
rs.MoveNext
Loop
rs.Open"SELECT ACCESSION_NO,TITLE,PUB_ID_NAME,CLASS_NO INTO NewTable FROM CATS",conn,adOpenStatic, adLockOptimistic
Set rs = Nothing

by expending the table, I see a sub list like below:
database diagrams
Tables
views
synonyms
programability
security


can i attach view of a table to listview control like a table attached to listview control

Thanks in advance



ch.s.deekshitulu


sorry you mean populate listview with table data?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

deekshitulu
Starting Member

8 Posts

Posted - 2012-09-16 : 23:26:54
sir,
actual fact is i am working in a library. about one lakh books data is entered in sql server 2005 database file. But I have developed a small project in vb6 as a front end with MS access back end. re entry of all the data is laborious job. to avoid this i wish to trasfer data from sql table to ms access table via listview control. for the purpose first i try to attach the sql table to listview control, it is successful, But I unable to send the data in listview control to a table with same and with same column in access database which is using back end in my project. For these purpose i put a save button in my Form and wrote code as above, But i am not succeed till now

I request your kind cooperation in this matter.

Thanks in advance

ch.s.deekshitulu
Go to Top of Page

deekshitulu
Starting Member

8 Posts

Posted - 2012-09-18 : 01:48:50
Mr.Viskhm
please respond to my topic

Thanks

ch.s.deekshitulu
Go to Top of Page
   

- Advertisement -