Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Closed Points: 25 Time: 18:37 - Apr 24, 2007  

aristud

Trying to add date column to listview

I am trying to retrieve data from a table in MS Access with VisualBasic. When the Date data type is set to date/time in access, the queries run fine, but I receive an error and it will not populate the listview. When I change the data type to text it will populate the listview, but the queries return the wrong information.

-------------------------------------------------------
Error:
An unhandled exception of type
'System.Reflection.AmbiguousMatchException' occured in
microsoft.visualbasic.dll

Additional information: No accessible overloaded
'ListViewItemCollection.Add' can be called without a narrowing conversion.
--------------------------------------------------------

Dim cnnConnection As New OleDb.OleDbConnection
cnnConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb"
cnnConnection.Open()

Dim strSQL As String = "SELECT * FROM TableName ORDER BY Date DESC;"
Dim adpDataAdapter As New OleDb.OleDbDataAdapter(strSQL, cnnConnection)
cnnConnection.Close()

Dim dstDataSet As New DataSet

adpDataAdapter.Fill(dstDataSet, "TableName")

Dim rowDataRow As DataRow
Dim litListViewItem As ListViewItem

For Each rowDataRow In dstDataSet.Tables("TableName").Rows
litListViewItem = lvwListView.Items.Add(rowDataRow("Date")
itListViewItem.SubItems.Add(rowDataRow("Item1"))
itListViewItem.SubItems.Add(rowDataRow("Item2"))
itListViewItem.SubItems.Add(rowDataRow("Item3"))
Next

Answer Discussion
Tutorials

 

nidhi

Date:: Apr 25, 2007

Time:: 04:15

I dont know if it will work with vb.net but u can tweak the SQL that u use and format the date
eg

Dim strSQL As String = "SELECT f1, f2, f3, format(f4,'Short Date') FROM TableName ORDER BY f4 DESC;"

nidhi

Date:: Apr 25, 2007

Time:: 04:32

yes it should work, I tried it in C#

nidhi

Date:: Apr 25, 2007

Time:: 04:32

I used OleDbCommand and OleDbDataReader to read it and treat the datefield as a string
i.e.

OleDbCommand oleCmd = new OleDbCommand("SELECT format(mydtefld,'short date') FROM tblDates", oleConn);

and gettting that value worked like this

Console.WriteLine(oleRead.GetString(0).ToString());


so yes, u should be able to use the format command. It does mean u have to specify each column in your query though

PeterNZ

Date:: Apr 26, 2007

Time:: 15:25

One note: oleRead.GetString(0) returns a string, so why do you add a .ToString() to it?

Cheers

Peter

aristud

Date:: Apr 26, 2007

Time:: 17:45

Thanks!

Question Answered

This question has been closed, and points have been rewarded to the following experts:


nidhi: 25

You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

No tutorials have been submitted yet. Want to be the first?

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10354

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es