Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / January 2005



Tip: Looking for answers? Try searching our database.

default value in field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lex Luthor - 25 Jan 2005 09:26 GMT
how can i get default value field in a db like .mdb , swl server and mysql
with asp programming ??
Evertjan. - 25 Jan 2005 09:41 GMT
Lex Luthor wrote on 25 jan 2005 in microsoft.public.inetserver.asp.db:

> how can i get default value field in a db like .mdb , swl server and
> mysql with asp programming ??

Something like this?

SQL=
"UPDATE myTable SET myField='myDefault value' "&_
"WHERE myField='' OR isNull(myField)"

Signature

Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Lex Luthor - 25 Jan 2005 11:16 GMT
i want to GET no SET..
> Lex Luthor wrote on 25 jan 2005 in microsoft.public.inetserver.asp.db:
>
[quoted text clipped - 6 lines]
> "UPDATE myTable SET myField='myDefault value' "&_
> "WHERE myField='' OR isNull(myField)"
Evertjan. - 25 Jan 2005 15:30 GMT
Lex Luthor wrote on 25 jan 2005 in microsoft.public.inetserver.asp.db:
> "Evertjan." <exjxw.hannivoort@interxnl.net> ha scritto nel messaggio
>> Lex Luthor wrote on 25 jan 2005 in microsoft.public.inetserver.asp.db:
[quoted text clipped - 9 lines]
>
> i want to GET no SET..

[please do not toppost on usenet]

Sorry, but that makes no sense to me, Lex.

What is a default value of a field if it is not set that way?

Signature

Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Bob Barrows [MVP] - 25 Jan 2005 16:16 GMT
> Lex Luthor wrote on 25 jan 2005 in microsoft.public.inetserver.asp.db:
>> "Evertjan." <exjxw.hannivoort@interxnl.net> ha scritto nel messaggio
[quoted text clipped - 17 lines]
>
> What is a default value of a field if it is not set that way?

Many rdbms' allow designers to specify default values as part of the
database schema. These values are inserted into new records if no value is
provided in the insert statement for the field for which a default value has
been created. For example, in SQL Server, you could do this:
CREATE TABLE dbo.Calendar
(
   cal_date       datetime NOT NULL,
   cal_start_time datetime NOT NULL,
   cal_end_time   datetime NOT NULL,
   day_type       char(1)
       CONSTRAINT DF_Calendardaytype
       DEFAULT 'w' NOT NULL,
   CONSTRAINT PK__Calendar__5CA1C101
       PRIMARY KEY CLUSTERED (cal_date)
  ON [PRIMARY]
)

The day_type column has a default of 'w', so this insert statement:
INSERT INTO dbo.Calendar
(cal_date,
 cal_start_time,
 cal_end_time)
VALUES
('20050125',
 '07:00',
 '15:00')

Will result in a record whose day_type contains 'w'.

I'm assuming this is the property whose value he wishes to retrieve.

Bob Barrows

Signature

Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Lex Luthor - 26 Jan 2005 15:30 GMT
not sense
> > Lex Luthor wrote on 25 jan 2005 in microsoft.public.inetserver.asp.db:
> >> "Evertjan." <exjxw.hannivoort@interxnl.net> ha scritto nel messaggio
[quoted text clipped - 50 lines]
>
> Bob Barrows
Bob Barrows [MVP] - 25 Jan 2005 12:02 GMT
> how can i get default value field in a db like .mdb , swl server and
> mysql with asp programming ??

You'll need to ask about mysql in a mysql group, but the value of the
default property can be retrieved form the other two via ADOX in the case of
Jet databases, and system views and procedures in SQL Server. Start here:
http://www.aspfaq.com/show.asp?id=2177
http://msdn.microsoft.com/library/en-us/ado270/htm/admscadoddloverview.asp
http://msdn.microsoft.com/library/en-us/oledb/htm/oledbprovjet_provider_specific
_properties_in_dbpropset_jetoledb_column.asp


Bob Barrows

Signature

Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Lex Luthor - 26 Jan 2005 08:10 GMT
an example please..
>> how can i get default value field in a db like .mdb , swl server and
>> mysql with asp programming ??
[quoted text clipped - 8 lines]
>
> Bob Barrows
Bob Barrows [MVP] - 26 Jan 2005 13:13 GMT
?
Everything you need to know is covered in these articles, especially if you
supplement the SQL Server examples with some reading in SQL Books Online.
For example, for SQL Server, here's a copy-paste from the aspfaq article
(with a slight modification to eliminate the dynamic sql, and another
modification to show all the field values of the  returned recordset):

<%
   dbname = "databasename"
   tablename = "tablename"

   ConnStr = "Provider=SQLOLEDB; Network=DBMSSOCN;" & _
       "Data Source=<x.x.x.x>;" & _
       "User Id=<uid>; Password=<pwd>;" & _
       "Initial Catalog=" & dbname

   set adodbConn = CreateObject("ADODB.Connection")
   adodbConn.Open ConnStr
   set rs = CreateObject("ADODB.Recordset")
   rs.cursorlocation = 3    'adUseClient
   adodbConn.sp_columns tablename,rs
   set rs.activeconnection = nothing
   adodbConn.Close: set adodbConn = nothing
   Response.Write "<TABLE><TR>"
   for each fld in rs.Fields
       Response.Write "<TD>" & fld.name & "</TD>"
   next
   Response.Write "</TR><TD>"
   str = rs.GetString(2,,"</TD><TD>","</TD></TR><TR><TD>","&nbsp;")
   rs.close: set rs = nothing
   str=left(str,len(str)-8)
   response.write str
   response.write "</TABLE>"
%>

Substitute your specific information, run this code and look at the
COLUMN_DEF field.

For Access, it is a little harder.

Actually, come to think of it, you may be able to use OpenSchema for all of
your databases. Try this:
<%
   dbname = "databasename"
   tablename = "tablename"

   ConnStr = "Provider=SQLOLEDB; Network=DBMSSOCN;" & _
       "Data Source=<x.x.x.x>;" & _
       "User Id=<uid>; Password=<pwd>;" & _
       "Initial Catalog=" & dbname

   set adodbConn = CreateObject("ADODB.Connection")
   adodbConn.Open ConnStr
   set rs = adodbConn.OpenSchema(adSchemaColumns, _
   Array(Empty,Empty,tablename))
   Response.Write "<TABLE border=1><TR>"
   for each fld in rs.Fields
       Response.Write "<TD>" & fld.name & "</TD>"
   next
   Response.Write "</TR><TD>"
   str = rs.GetString(2,,"</TD><TD>","</TD></TR><TR><TD>","&nbsp;")
   rs.close: set rs = nothing
   adodbConn.Close: set adodbConn = nothing

   str=left(str,len(str)-8)
   response.write str
   response.write "</TABLE>"
%>

You can make this return information about a specific column by changing
this:
   set rs = adodbConn.OpenSchema(adSchemaColumns, _
   Array(Empty,Empty,tablename))

to this:
   col = "SomeColumn"
   set rs = adodbConn.OpenSchema(adSchemaColumns, _
   Array(Empty,Empty,tablename, col))

This workd with both SQL Server and Jet. I don't know if it will work with
MySQL, but i suspect that it will.

Bob Barrows

> an example please..

Signature

Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Lex Luthor - 26 Jan 2005 15:29 GMT
i must get a key name with a simple query
as select @@identity that response key value but not key name

> ?
> Everything you need to know is covered in these articles, especially if you
[quoted text clipped - 81 lines]
>
> > an example please..
Bob Barrows [MVP] - 26 Jan 2005 17:10 GMT
> i must get a key name with a simple query
> as select @@identity that response key value but not key name

I do not have a clue as to what you are talking about. Anyone else?

Bob Barrows
Signature

Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Roland Hall - 26 Jan 2005 17:46 GMT
: > i must get a key name with a simple query
: > as select @@identity that response key value but not key name
: >
: I do not have a clue as to what you are talking about. Anyone else?

Ya'.  It sounds like you don't have a clue. (O:=.

Signature

Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp

Lex Luthor - 27 Jan 2005 08:22 GMT
i want to know the field name as "select @@identity" value.. the last
>> i must get a key name with a simple query
>> as select @@identity that response key value but not key name
>>
> I do not have a clue as to what you are talking about. Anyone else?
>
> Bob Barrows
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.