Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to use the query builder to concatenate an autonumber field with a date field so the are displayed in a combo box.

 


SELECT [log_no] & " " & [dated] AS logno
FROM tblLogNumbers;

 

works fine in Access, but not in VS?

 

I have tried many attempts including;

 


SELECT str(log_no) + ' ' + str(dated AS logno
FROM tblLogNumbers;

 

which all fail:(

My website
Posted

SELECT Cast([log_no] as varchar(255) ) + ' ' + Cast([dated] as varchar(255) ) AS logno

FROM tblLogNumbers

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • *Experts*
Posted

You can't use Cast in Access (that's SQL Server syntax). In Access you must use Format, something like:

SELECT Format(log_no) + ' ' + Format(dated) AS logno
FROM tblLogNumbers

 

Your original code, using Str, should work too but you were missing a closing parenthesis.

 

If this doesn't work in ".NET", then you'll have to show us the code you're using to call Access (DataReader, DataSet with DataAdapter, etc.).

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

nope:(

 

error message states string not recognized as valid date along with loads of other errors???

 

re the missing ) that was a typo here, my code did have it in it tho:(

My website
Posted

sorry. . misread. . . does this work?

 

SELECT cstr(log_no) + ' ' + Format([dated],"yyyymmdd") AS logno

FROM tblLogNumbers

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

I get this error :

 

couldn't store <130/06/2004> in logno column expected type is date time'

 

:confused:

My website
Posted

Think he means <30/06/2004>

 

This is his son, hes texting me what to post and he had 130 must of been typo

My website
  • *Experts*
Posted

Nope, I think 130 is right.

 

You're getting an error filling a DataSet, I assume, where the column that you're matching to is defined as a DateTime. I'm betting your DataSet is predefined (from an XSD file maybe) and the logno column is defined as DateTime.

 

You're attempting to piece together a Number and a Date and return that as a string from the Database. So if log_no is 1 and dated is "6/30/2004" then I'd expect:

130/6/2004

 

The first "1" is the log_no, the "30/6/2004" is the date.

 

I have no idea why you'd want to piece together a number and date as ONE column in your DataSet... but your DataSet better have that defined as a string column - and I'm guessing it's not.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

OK I hve is sussed;

 


SELECT     '[' + cstr(log_no) + '] ' + format(logged_dated, 'dd/mm/yyyy') + ' ' + LEFT(description, 40) AS log_detaill, log_no
FROM         tblLog
ORDER BY log_no

 

I am doing this so that the log detail combo box displays the log number, the date and the first 40 characters of the description in one column.

 

thus..... [23] 30/8/2004 This is some text from the log

 

Thnx:)

My website

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...