473,725 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JScript Erroneously Says (oRecordSet (oItem).Attribu tes & 0x4) = 0

How can I get the recordset attributes for a table field in SQL Server 2000
to report the field updatable attribute correctly ... mine keeps saying the
fields are not updatable? That is, ( oRecordSet ( oItem ).Attributes & 0x4)
is always 0 for every field on SQL Server 2000

Example code:

var sSQL = 'SELECT TOP 1 * FROM [' + sTableName + '] WHERE ' + sUniqueField
+ '=' + sUniqueValue + ';';

oRecordSet.Open ( sSQL, oConnection, adOpenStatic, adLockOptimisti c );

// get the data from the form, updating the recordset

var e = new Enumerator ( Request.Form );

while ( !e.atEnd ( ) )

{

var oItem = e.item();

if ( ( oRecordSet ( oItem ).Attributes & 0x4) != 0 ) // 4 ==
adFldUpdatable, 8 == adFldUnknownUpd atable

{

oRecordSet ( oItem ).Value = ( FixNull( Request.Form( oItem ) ) == '' ?
null : Request.Form ( oItem ));

// if the unique field was updated use the new answer

if ( oItem == sUniqueField )

{

// keep it wrapped in "" if it used to be

if ( sUniqueValue.ch arAt ( 0 ) == "'" )

sUniqueValue = "'" + Request.Form ( oItem ) + "'";

else

sUniqueValue = "" + Request.Form ( oItem );

}

}

}

e.moveNext ( );

}

oRecordSet.Upda te ( );
Jul 19 '05 #1
3 2580
A couple possibilities:

a) The Top statement is resulting in a non-updatable resultset (I'm not sure
about this one). Why do you need Top 1 if you are filtering on a unique
column? it makes me suspect that the column is not unique which may lead to
the situation in option c.
b) The Provider you are using is misreporting the attribute and the column
actually is updatable
c) Your table has no primary key or unique index to allow ADO to identify
the record being updated

Bottom line: you should not use recordsets for data modification. Use SQL
DML (Insert, Update, and Delete queries) instead. Cursors are evil.

Bob Barrows

Dan Sikorsky wrote:
How can I get the recordset attributes for a table field in SQL
Server 2000 to report the field updatable attribute correctly ...
mine keeps saying the fields are not updatable? That is, ( oRecordSet
( oItem ).Attributes & 0x4) is always 0 for every field on SQL Server
2000

Example code:

var sSQL = 'SELECT TOP 1 * FROM [' + sTableName + '] WHERE ' +
sUniqueField + '=' + sUniqueValue + ';';

oRecordSet.Open ( sSQL, oConnection, adOpenStatic, adLockOptimisti c );

// get the data from the form, updating the recordset

var e = new Enumerator ( Request.Form );

while ( !e.atEnd ( ) )

{

var oItem = e.item();

if ( ( oRecordSet ( oItem ).Attributes & 0x4) != 0 ) // 4 ==
adFldUpdatable, 8 == adFldUnknownUpd atable

{

oRecordSet ( oItem ).Value = ( FixNull( Request.Form( oItem ) )
== '' ? null : Request.Form ( oItem ));

// if the unique field was updated use the new answer

if ( oItem == sUniqueField )

{

// keep it wrapped in "" if it used to be

if ( sUniqueValue.ch arAt ( 0 ) == "'" )

sUniqueValue = "'" + Request.Form ( oItem ) + "'";

else

sUniqueValue = "" + Request.Form ( oItem );

}

}

}

e.moveNext ( );

}

oRecordSet.Upda te ( );



Jul 19 '05 #2
Thanks for the insight Bob ... I'll look into your analysis.

The only reason to use the SELECT TOP 1 * FROM ... is to get back the
attributes of each field in the table ... whether or not there are any
records. Not only do I use this technique here for an UPDATE action, but I
heavily use it for creating ASP form fields using a template. By passing in
the table name to a generic form routine, I can automatically show only the
table's form fields that should be shown for the SQL INSERT/UPDATE that is
executed when the form is submitted.

Admittedly, this technique works well for the LAN web forms that are used
internally via an Access2000 database, and I recently have be moving
internal Access2000 databases to SQL Server 2000 and have run across this
problem.

The connection string includes 'Provider=SQLOL EDB.1; ...'

There is a primary key declared for the table; the usual long integer that
is incremented by one to get the next key.

Do you of a way, in jscript, to determine if a table's field is updatable
(without maintaining a list of field names in a string variable), directly
by querying the SQL Server table, so as to use knowledge that is already
specified somewhere in SQL Server?

Thank you kindly,
Dan Sikorsky
"Bob Barrows" <re*******@yaho o.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
A couple possibilities:

a) The Top statement is resulting in a non-updatable resultset (I'm not sure about this one). Why do you need Top 1 if you are filtering on a unique
column? it makes me suspect that the column is not unique which may lead to the situation in option c.
b) The Provider you are using is misreporting the attribute and the column
actually is updatable
c) Your table has no primary key or unique index to allow ADO to identify
the record being updated

Bottom line: you should not use recordsets for data modification. Use SQL
DML (Insert, Update, and Delete queries) instead. Cursors are evil.

Bob Barrows

Dan Sikorsky wrote:
How can I get the recordset attributes for a table field in SQL
Server 2000 to report the field updatable attribute correctly ...
mine keeps saying the fields are not updatable? That is, ( oRecordSet
( oItem ).Attributes & 0x4) is always 0 for every field on SQL Server
2000

Example code:

var sSQL = 'SELECT TOP 1 * FROM [' + sTableName + '] WHERE ' +
sUniqueField + '=' + sUniqueValue + ';';

oRecordSet.Open ( sSQL, oConnection, adOpenStatic, adLockOptimisti c );

// get the data from the form, updating the recordset

var e = new Enumerator ( Request.Form );

while ( !e.atEnd ( ) )

{

var oItem = e.item();

if ( ( oRecordSet ( oItem ).Attributes & 0x4) != 0 ) // 4 ==
adFldUpdatable, 8 == adFldUnknownUpd atable

{

oRecordSet ( oItem ).Value = ( FixNull( Request.Form( oItem ) )
== '' ? null : Request.Form ( oItem ));

// if the unique field was updated use the new answer

if ( oItem == sUniqueField )

{

// keep it wrapped in "" if it used to be

if ( sUniqueValue.ch arAt ( 0 ) == "'" )

sUniqueValue = "'" + Request.Form ( oItem ) + "'";

else

sUniqueValue = "" + Request.Form ( oItem );

}

}

}

e.moveNext ( );

}

oRecordSet.Upda te ( );


Jul 19 '05 #3
Bob,

I'll use the select * from tbl where 1=2 idea.

My primary usage for determining the 'updatableness' of a field is for a
generic asp page to prompt for only fields that are insertable or updatable,
stripping out such fields as the primary key, all foreign keys, and fields
declared in SQL Server to not have permission for specific users.

In my JScript, I do use a 'select max(id)+1 as ID from tbl ' to generate the
next primary key, followed by an insert statement. This is a carryover from
the Access2000 design, and I should use an IDENTITY field instead.

Dan

"Bob Barrows" <re*******@yaho o.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I still don't see why TOP 1 is necessary. If you just want a list of fields, you can do:
select * from table where 1=2

As to whether or not the field is updatable, if the provider is not
supplying the necessary attribute information, you can open a recordset,
disconnect it by setting its activeconnectio n property to nothing, and
attempt to update the fields, catching the error if the field is not
updatable. That way, you won't effect the source data in the database.

In my experience, however, all columns except the IDENTITY column are
updatable. When you say " ... incremented by one to get the next key.", do
you mean that you are using the builtin IDENTITY column? Or have you created your own process to get the next key. If the column is not an IDENTITY, it
should be updatable. You can determine whether a column is an IDENTITY
column by running the sp_columns procedure against the table and checking to see if the TYPE_NAME column contains the word "identity". I would do this in a stored procedure to avoid bringing all the column rows back to your asp
page. You could have the stored procedure return only the name of the
IDENTITY.

Another situation that may effect updatability is when the column is
involved in a foreign key relationship (or has some other constraint defined that may prevent any updates). This is another case where you would want to wrap the code that checks for this (you can use the INFORMATION_SCH EMA views or the relevant system stored procedures - see BOL) in a stored procedure.

I never do generic stuff like this: it's much too detrimental to performance and scalability. Using Select * and cursors for data modifications pretty
much guarantees that you are sending too much data across the wire and
maintaining table locks for too long. In addition, failure to utilize stored procedures can have a severe impact on performance and scalability:
http://msdn.microsoft.com/library/te...kbench_topic15
(see the Dynamic SQL vs. Stored Procedures test)
I'm going to have to stop here. I think my boss is looking for me ;-)

HTH,
Bob Barrows

Dan Sikorsky wrote:
Thanks for the insight Bob ... I'll look into your analysis.

The only reason to use the SELECT TOP 1 * FROM ... is to get back the
attributes of each field in the table ... whether or not there are any
records. Not only do I use this technique here for an UPDATE action,
but I heavily use it for creating ASP form fields using a template.
By passing in the table name to a generic form routine, I can
automatically show only the table's form fields that should be shown
for the SQL INSERT/UPDATE that is executed when the form is submitted.

Admittedly, this technique works well for the LAN web forms that are
used internally via an Access2000 database, and I recently have be
moving internal Access2000 databases to SQL Server 2000 and have run
across this problem.

The connection string includes 'Provider=SQLOL EDB.1; ...'

There is a primary key declared for the table; the usual long integer
that is incremented by one to get the next key.

Do you of a way, in jscript, to determine if a table's field is
updatable (without maintaining a list of field names in a string
variable), directly by querying the SQL Server table, so as to use
knowledge that is already specified somewhere in SQL Server?

Thank you kindly,
Dan Sikorsky
"Bob Barrows" <re*******@yaho o.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
A couple possibilities:

a) The Top statement is resulting in a non-updatable resultset (I'm
not sure about this one). Why do you need Top 1 if you are filtering
on a unique column? it makes me suspect that the column is not
unique which may lead to the situation in option c.
b) The Provider you are using is misreporting the attribute and the
column actually is updatable
c) Your table has no primary key or unique index to allow ADO to
identify the record being updated

Bottom line: you should not use recordsets for data modification.
Use SQL DML (Insert, Update, and Delete queries) instead. Cursors
are evil.

Bob Barrows

Dan Sikorsky wrote:
How can I get the recordset attributes for a table field in SQL
Server 2000 to report the field updatable attribute correctly ...
mine keeps saying the fields are not updatable? That is, (
oRecordSet ( oItem ).Attributes & 0x4) is always 0 for every field
on SQL Server 2000

Example code:

var sSQL = 'SELECT TOP 1 * FROM [' + sTableName + '] WHERE ' +
sUniqueField + '=' + sUniqueValue + ';';

oRecordSet.Open ( sSQL, oConnection, adOpenStatic, adLockOptimisti c
);

// get the data from the form, updating the recordset

var e = new Enumerator ( Request.Form );

while ( !e.atEnd ( ) )

{

var oItem = e.item();

if ( ( oRecordSet ( oItem ).Attributes & 0x4) != 0 ) // 4 ==
adFldUpdatable, 8 == adFldUnknownUpd atable

{

oRecordSet ( oItem ).Value = ( FixNull( Request.Form( oItem ) )
== '' ? null : Request.Form ( oItem ));

// if the unique field was updated use the new answer

if ( oItem == sUniqueField )

{

// keep it wrapped in "" if it used to be

if ( sUniqueValue.ch arAt ( 0 ) == "'" )

sUniqueValue = "'" + Request.Form ( oItem ) + "'";

else

sUniqueValue = "" + Request.Form ( oItem );

}

}

}

e.moveNext ( );

}

oRecordSet.Upda te ( );


Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
806
by: jason | last post by:
There's a couple of really good examples of how custom attributes and reflecion can be used in C# and other .NET languages to build very loose but very testable architectures at http://www.objectmonkey.com/index.php?A=getcolumnpiece&Ar=p=32^c=5^i=14^
1
1877
by: thejackofall | last post by:
Hi. I have a checkbox column in my datagrid like this: <Columns> <asp:TemplateColumn HeaderText=" "> <ItemTemplate> <asp:CheckBox ID='Selection' runat="server"></asp:CheckBox> <asp:Label ID="SelectID" Visible="False" Text='<%#
4
2731
by: Wiktor Zychla | last post by:
Hello, for some reason I need to use attributes in ILAsm code and read these attributes in C# code. My problem is with the attribute declaration inside ILAsm code. I know that I define any attribute by using ILasm's ".custom" keyword but I do not understand how to initialize the attribute Value blob when the attribute contains some fields. I just do not understand that binary format: ..custom instance void MyAttribute::.ctor(bool) =...
5
2077
by: Bob N | last post by:
I have an ASP.NET web page -- several auto-post back DropDownLists that perform a query against a relatively large database (3 to 4 seconds delay) that repopulate a couple of datagrids, comboboxes and a chart (using dotnetCharting control) on the same page. This works just fine on its own. However, when I integrated the page into the rest of the site, it is then placed inside a frameset. Again, the page seems to work fine EXCEPT under the...
10
1345
by: SergioT | last post by:
Hi I wanna to create a jscript function that sets the value of a textbox into a datagrid, But the problem is How can I obtain the name of the textbox and send it to my jscript function???? The textbox is in a TemplateColumn The Idea is sent to the funcion the name of the control and then pass it to another window and then this child window must set the values of the control. But for simplicity the problem get reduced to obtain the...
6
31447
by: Tony | last post by:
The w3schools HTML tag reference for <textarea> http://www.w3schools.com/tags/tag_textarea.asp says that the attributes 'cols' and 'rows' are REQUIRED attributes for the textarea tag. Looking at the HTML 4.01 specification I see this, too. What I'm wondering is - 'cols' & 'rows' determines the height & width of a textarea. So shouldn't that be something that is handled by CSS instead? What would be the practical consequence of leaving...
1
3474
by: Andrew Wan | last post by:
How can VBScript code access JScript code variables in the same ASP page? <SCRIPT LANGAUGE="VBScript"> Dim a a = 10 </SCRIPT> <SCRIPT LANGUAGE="JScript"> Response.Write(a); </SCRIPT>
2
2140
by: james_027 | last post by:
hi everyone, I am now in chapter 5 of Dive Into Python and I have some question about it. From what I understand in the book is you define class attributes & data attributes like this in python class Book: total # is a class attribute
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.