473,671 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Execute the insert command with boolean

my insert works, but without the boolean value contentavailabl e.
When I try to insert this boolean I get a data mismatch error.
this "contentavailab le" is an asp.net checkbox

I use a ms access dbase.

any ideas? THX

here's the code:

commInsert.Exec ute("INSERT INTO tbl_contents (contenttypeID, contentEN,
contentFR, contentNL, contentDU, contentdescript ionEN, contentdescript ionFR,
contentdescript ionNL, contentdescript ionDU, contentavailabl e, contentorder)
VALUES('" & ctype(contentty peID.selectedit em.value,intege r) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text & "','" &
contentDU.text & "','" & contentdescript ionEN.text & "','" &
contentdescript ionFR.text & "','" & contentdescript ionNL.text & "','" &
contentdescript ionDU.text & "','" & contentavailabl e.checked & "','" &
contentorder.te xt & "');")
Nov 18 '05 #1
6 3463
It looks like the Boolean field is being inserted as a string. You may need
to drop the apostrophe on either side and use something like

contentavailabl e.Checked.ToStr ing

"nicholas" <mu********@hot mail.com> wrote in message
news:uJ******** ******@tk2msftn gp13.phx.gbl...
my insert works, but without the boolean value contentavailabl e.
When I try to insert this boolean I get a data mismatch error.
this "contentavailab le" is an asp.net checkbox

I use a ms access dbase.

any ideas? THX

here's the code:

commInsert.Exec ute("INSERT INTO tbl_contents (contenttypeID, contentEN,
contentFR, contentNL, contentDU, contentdescript ionEN,
contentdescript ionFR,
contentdescript ionNL, contentdescript ionDU, contentavailabl e,
contentorder)
VALUES('" & ctype(contentty peID.selectedit em.value,intege r) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text & "','" &
contentDU.text & "','" & contentdescript ionEN.text & "','" &
contentdescript ionFR.text & "','" & contentdescript ionNL.text & "','" &
contentdescript ionDU.text & "','" & contentavailabl e.checked & "','" &
contentorder.te xt & "');")


Nov 18 '05 #2
Ken Cox [Microsoft MVP] <BA************ @sympatico.ca> typed:
It looks like the Boolean field is being inserted as a string. You
may need to drop the apostrophe on either side and use something like

contentavailabl e.Checked.ToStr ing


Just to remember you that it's better to don't use this kind of SQL
Statement in your code. Your application risk SQL Injection attacks (see
this useful article:
http://msdn.microsoft.com/msdnmag/is.../SQLInjection/)

Don't forget to review your code to avoid SQL Injection ;-)

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer
Nov 18 '05 #3
indeed
THX

"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:u8******** ******@TK2MSFTN GP10.phx.gbl...
It looks like the Boolean field is being inserted as a string. You may need to drop the apostrophe on either side and use something like

contentavailabl e.Checked.ToStr ing

"nicholas" <mu********@hot mail.com> wrote in message
news:uJ******** ******@tk2msftn gp13.phx.gbl...
my insert works, but without the boolean value contentavailabl e.
When I try to insert this boolean I get a data mismatch error.
this "contentavailab le" is an asp.net checkbox

I use a ms access dbase.

any ideas? THX

here's the code:

commInsert.Exec ute("INSERT INTO tbl_contents (contenttypeID, contentEN,
contentFR, contentNL, contentDU, contentdescript ionEN,
contentdescript ionFR,
contentdescript ionNL, contentdescript ionDU, contentavailabl e,
contentorder)
VALUES('" & ctype(contentty peID.selectedit em.value,intege r) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text & "','" & contentDU.text & "','" & contentdescript ionEN.text & "','" &
contentdescript ionFR.text & "','" & contentdescript ionNL.text & "','" &
contentdescript ionDU.text & "','" & contentavailabl e.checked & "','" &
contentorder.te xt & "');")

Nov 18 '05 #4
Yes, you're right.
I didn't know about this.

Could you help me change my code in a good way?
I know how to do it when I work with an SQL-server, but as for this
application I use a ms Access (mdb) database and as I want to retrieve the
ID of the newly created record, this is the only code combination that
works. (and I can assure you, I tried a lot of code combinations !!)

So If you could help me implement this code, but with @parameters, would be
great !

THX a lot,
Frederic

Here's my code executed on the on_click event of an asp.net button

######## code start #######

'define where the connectionstrin g is here:
Dim MyConnectionStr ing as String =
ConfigurationSe ttings.AppSetti ngs("Connection String")

dim commInsert = Server.CreateOb ject("ADODB.Con nection")
dim rsnewID = Server.CreateOb ject("ADODB.rec ordset")
commInsert.Open (MyConnectionSt ring) ' Replace with your OLE DB
connection string.
commInsert.Exec ute("INSERT INTO tbl_contents (contenttypeID, contentEN,
contentFR, contentNL, contentDU, contentdescript ionEN, contentdescript ionFR,
contentdescript ionNL, contentdescript ionDU, contentavailabl e, contentorder)
VALUES('" & ctype(contentty peID.selectedit em.value,intege r) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text & "','" &
contentDU.text & "','" & contentdescript ionEN.text & "','" &
contentdescript ionFR.text & "','" & contentdescript ionNL.text & "','" &
contentdescript ionDU.text & "'," & contentavailabl e.checked & ",'" &
contentorder.te xt & "');")

rsNewID = commInsert.Exec ute("SELECT @@IDENTITY ")
dim intNewID = rsNewID(0).valu e
rsNewID.Close
rsNewID = Nothing
commInsert.Clos e
commInsert = Nothing

response.write( intnewid)
######### end of code ########
I also had to add this: AspCompat="true " to the page directive to make it
work.


"Davide Vernole [MVP]" <da****@online. knodev.com> wrote in message
news:OX******** ******@TK2MSFTN GP11.phx.gbl...
Ken Cox [Microsoft MVP] <BA************ @sympatico.ca> typed:
It looks like the Boolean field is being inserted as a string. You
may need to drop the apostrophe on either side and use something like

contentavailabl e.Checked.ToStr ing


Just to remember you that it's better to don't use this kind of SQL
Statement in your code. Your application risk SQL Injection attacks (see
this useful article:
http://msdn.microsoft.com/msdnmag/is.../SQLInjection/)

Don't forget to review your code to avoid SQL Injection ;-)

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer

Nov 18 '05 #5
nicholas <mu********@hot mail.com> typed:
Yes, you're right.
I didn't know about this.

Could you help me change my code in a good way?
I know how to do it when I work with an SQL-server, but as for this
application I use a ms Access (mdb) database and as I want to
retrieve the ID of the newly created record, this is the only code
combination that works. (and I can assure you, I tried a lot of code
combinations !!)

So If you could help me implement this code, but with @parameters,
would be great !

THX a lot,
Frederic

Here's my code executed on the on_click event of an asp.net button

######## code start #######

'define where the connectionstrin g is here:
Dim MyConnectionStr ing as String =
ConfigurationSe ttings.AppSetti ngs("Connection String")

dim commInsert = Server.CreateOb ject("ADODB.Con nection")
dim rsnewID = Server.CreateOb ject("ADODB.rec ordset")
commInsert.Open (MyConnectionSt ring) ' Replace with your OLE DB
connection string.
commInsert.Exec ute("INSERT INTO tbl_contents (contenttypeID,
contentEN, contentFR, contentNL, contentDU, contentdescript ionEN,
contentdescript ionFR, contentdescript ionNL, contentdescript ionDU,
contentavailabl e, contentorder) VALUES('" &
ctype(contentty peID.selectedit em.value,intege r) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text &
"','" & contentDU.text & "','" & contentdescript ionEN.text & "','" &
contentdescript ionFR.text & "','" & contentdescript ionNL.text & "','"
& contentdescript ionDU.text & "'," & contentavailabl e.checked & ",'"
& contentorder.te xt & "');")

rsNewID = commInsert.Exec ute("SELECT @@IDENTITY ")
dim intNewID = rsNewID(0).valu e
rsNewID.Close
rsNewID = Nothing
commInsert.Clos e
commInsert = Nothing

response.write( intnewid)
######### end of code ########
I also had to add this: AspCompat="true " to the page directive to
make it work.


Your are OT. Here we talk about .NET. However, try to see this link
http://support.microsoft.com/kb/232144/EN-US/. Maybe you could find
something interesting for you.

See this for more info about CommandParamete r:
http://support.microsoft.com/default...ata/adofaq.asp
http://www.devguru.com/Technologies/...ollection.html
http://www.w3schools.com/ado/met_com...eparameter.asp

......see google for more ;-)

HTH

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer
Nov 18 '05 #6
nicholas <mu********@hot mail.com> typed:
Yes, you're right.
I didn't know about this.

Could you help me change my code in a good way?
I know how to do it when I work with an SQL-server, but as for this
application I use a ms Access (mdb) database and as I want to
retrieve the ID of the newly created record, this is the only code
combination that works. (and I can assure you, I tried a lot of code
combinations !!)

So If you could help me implement this code, but with @parameters,
would be great !

THX a lot,
Frederic

Here's my code executed on the on_click event of an asp.net button

######## code start #######

'define where the connectionstrin g is here:
Dim MyConnectionStr ing as String =
ConfigurationSe ttings.AppSetti ngs("Connection String")

dim commInsert = Server.CreateOb ject("ADODB.Con nection")
dim rsnewID = Server.CreateOb ject("ADODB.rec ordset")
commInsert.Open (MyConnectionSt ring) ' Replace with your OLE DB
connection string.
commInsert.Exec ute("INSERT INTO tbl_contents (contenttypeID,
contentEN, contentFR, contentNL, contentDU, contentdescript ionEN,
contentdescript ionFR, contentdescript ionNL, contentdescript ionDU,
contentavailabl e, contentorder) VALUES('" &
ctype(contentty peID.selectedit em.value,intege r) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text &
"','" & contentDU.text & "','" & contentdescript ionEN.text & "','" &
contentdescript ionFR.text & "','" & contentdescript ionNL.text & "','"
& contentdescript ionDU.text & "'," & contentavailabl e.checked & ",'"
& contentorder.te xt & "');")

rsNewID = commInsert.Exec ute("SELECT @@IDENTITY ")
dim intNewID = rsNewID(0).valu e
rsNewID.Close
rsNewID = Nothing
commInsert.Clos e
commInsert = Nothing

response.write( intnewid)
######### end of code ########
I also had to add this: AspCompat="true " to the page directive to
make it work.


Your are OT. Here we talk about .NET. However, try to see this link
http://support.microsoft.com/kb/232144/EN-US/. Maybe you could find
something interesting for you.

See this for more info about CommandParamete r:
http://support.microsoft.com/default...ata/adofaq.asp
http://www.devguru.com/Technologies/...ollection.html
http://www.w3schools.com/ado/met_com...eparameter.asp

......see google for more ;-)

HTH

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer
Nov 18 '05 #7

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

Similar topics

5
12410
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality provided by Informix. This is the problem: the execution of the translated SQL leaves the rows in the temp table correctly but raises error SQL0480N. It's very simple to try it: ------------
2
7621
by: Norman Fritag | last post by:
Hi there The below code executes some queries. As newbie I was wondering weather you are better of using connection execute or command execute to execute queries? I am asking as Gcnndoh.Execute "AppendDataEntrySummaryLevel2" causes a Run-time error '-2147217900 (80040e14). If I execute the query from the query editor it's working ok!! No messages!!!
5
15409
by: Annie | last post by:
hello guys, I have little experience working with C# and MS Access ... I am having an insert query with one datetime field and a boolean and couple of text and number fields as below: "Insert into order (OrderClientID, OrderDate, OrderOfferID, OrderIsSpecial, OrderShipment) Values (6, # 16/09/2005 2:38:51 PM # , 1 , 0 , 'hello there it is test')"
14
11138
by: technocrat | last post by:
db2 -t -v -f/home.../filename >output_file-name I have a java stored procedure..which has to run the above command...not sure how i can run this command through java.. any suggestions are appreciated..
0
1236
by: nano2k | last post by:
Hi I develop a client/server application using webservices. So, I have a client app and a webservice that responds to client app requests - nothin' new. In certain circumstances (namely, when importing data) I want some compiled code located in client app to be *transferred* to the webservice, optionally to make some bindings to the server side and to execute that code.
1
2179
by: Doc11 | last post by:
I'm trying to allow users insert data into a database using the form view. But when I click the insert button I get this error: Server Error in '/Customer Database' Application. -------------------------------------------------------------------------------- Incorrect syntax near 'nvarchar'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
1
1545
by: iprogrammer | last post by:
i m new to .net and db connectivity in .net using sql server.... i want to insert values from into a db test1 from a function register(); where i will pass values the function register will this syntax work... public void register(int mc,int pt) { SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Inetpub\wwwroot\WebSite1\App_Data\test.mdf;Integrated Security=True;User...
6
4428
by: Oliver | last post by:
I'm fairly new to DB2. I have been assigned to build a delete trigger that finds the data type of each of the table's fields so that the trigger can then build a string consisting of OLD values pre-wrapped in quote marks as needed. The deleted record's field values, all strung together as a single string, would then be inserted into a single archiving table (an architecture I inherited and cannot change). I've got the trigger doing...
3
2075
by: deneushasler | last post by:
Hello my name is Juan Jose. My problem is as follows. When I try to insert a record into a table (access) to control DetailsView Visual Web Developer 2005, when I run the page and insert a record pulse, whenever I get the following error: How could fix it?
0
8478
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
8397
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,...
0
8919
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8599
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
8670
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
7439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6230
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
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();...
2
1810
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.