473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Execute the insert command with boolean

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

I use a ms access dbase.

any ideas? THX

here's the code:

commInsert.Execute("INSERT INTO tbl_contents (contenttypeID, contentEN,
contentFR, contentNL, contentDU, contentdescriptionEN, contentdescriptionFR,
contentdescriptionNL, contentdescriptionDU, contentavailable, contentorder)
VALUES('" & ctype(contenttypeID.selecteditem.value,integer) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text & "','" &
contentDU.text & "','" & contentdescriptionEN.text & "','" &
contentdescriptionFR.text & "','" & contentdescriptionNL.text & "','" &
contentdescriptionDU.text & "','" & contentavailable.checked & "','" &
contentorder.text & "');")
Nov 18 '05 #1
6 3454
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

contentavailable.Checked.ToString

"nicholas" <mu********@hotmail.com> wrote in message
news:uJ**************@tk2msftngp13.phx.gbl...
my insert works, but without the boolean value contentavailable.
When I try to insert this boolean I get a data mismatch error.
this "contentavailable" is an asp.net checkbox

I use a ms access dbase.

any ideas? THX

here's the code:

commInsert.Execute("INSERT INTO tbl_contents (contenttypeID, contentEN,
contentFR, contentNL, contentDU, contentdescriptionEN,
contentdescriptionFR,
contentdescriptionNL, contentdescriptionDU, contentavailable,
contentorder)
VALUES('" & ctype(contenttypeID.selecteditem.value,integer) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text & "','" &
contentDU.text & "','" & contentdescriptionEN.text & "','" &
contentdescriptionFR.text & "','" & contentdescriptionNL.text & "','" &
contentdescriptionDU.text & "','" & contentavailable.checked & "','" &
contentorder.text & "');")


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

contentavailable.Checked.ToString


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**************@TK2MSFTNGP10.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

contentavailable.Checked.ToString

"nicholas" <mu********@hotmail.com> wrote in message
news:uJ**************@tk2msftngp13.phx.gbl...
my insert works, but without the boolean value contentavailable.
When I try to insert this boolean I get a data mismatch error.
this "contentavailable" is an asp.net checkbox

I use a ms access dbase.

any ideas? THX

here's the code:

commInsert.Execute("INSERT INTO tbl_contents (contenttypeID, contentEN,
contentFR, contentNL, contentDU, contentdescriptionEN,
contentdescriptionFR,
contentdescriptionNL, contentdescriptionDU, contentavailable,
contentorder)
VALUES('" & ctype(contenttypeID.selecteditem.value,integer) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text & "','" & contentDU.text & "','" & contentdescriptionEN.text & "','" &
contentdescriptionFR.text & "','" & contentdescriptionNL.text & "','" &
contentdescriptionDU.text & "','" & contentavailable.checked & "','" &
contentorder.text & "');")

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 connectionstring is here:
Dim MyConnectionString as String =
ConfigurationSettings.AppSettings("ConnectionStrin g")

dim commInsert = Server.CreateObject("ADODB.Connection")
dim rsnewID = Server.CreateObject("ADODB.recordset")
commInsert.Open(MyConnectionString) ' Replace with your OLE DB
connection string.
commInsert.Execute("INSERT INTO tbl_contents (contenttypeID, contentEN,
contentFR, contentNL, contentDU, contentdescriptionEN, contentdescriptionFR,
contentdescriptionNL, contentdescriptionDU, contentavailable, contentorder)
VALUES('" & ctype(contenttypeID.selecteditem.value,integer) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text & "','" &
contentDU.text & "','" & contentdescriptionEN.text & "','" &
contentdescriptionFR.text & "','" & contentdescriptionNL.text & "','" &
contentdescriptionDU.text & "'," & contentavailable.checked & ",'" &
contentorder.text & "');")

rsNewID = commInsert.Execute("SELECT @@IDENTITY ")
dim intNewID = rsNewID(0).value
rsNewID.Close
rsNewID = Nothing
commInsert.Close
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**************@TK2MSFTNGP11.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

contentavailable.Checked.ToString


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********@hotmail.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 connectionstring is here:
Dim MyConnectionString as String =
ConfigurationSettings.AppSettings("ConnectionStrin g")

dim commInsert = Server.CreateObject("ADODB.Connection")
dim rsnewID = Server.CreateObject("ADODB.recordset")
commInsert.Open(MyConnectionString) ' Replace with your OLE DB
connection string.
commInsert.Execute("INSERT INTO tbl_contents (contenttypeID,
contentEN, contentFR, contentNL, contentDU, contentdescriptionEN,
contentdescriptionFR, contentdescriptionNL, contentdescriptionDU,
contentavailable, contentorder) VALUES('" &
ctype(contenttypeID.selecteditem.value,integer) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text &
"','" & contentDU.text & "','" & contentdescriptionEN.text & "','" &
contentdescriptionFR.text & "','" & contentdescriptionNL.text & "','"
& contentdescriptionDU.text & "'," & contentavailable.checked & ",'"
& contentorder.text & "');")

rsNewID = commInsert.Execute("SELECT @@IDENTITY ")
dim intNewID = rsNewID(0).value
rsNewID.Close
rsNewID = Nothing
commInsert.Close
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 CommandParameter:
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********@hotmail.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 connectionstring is here:
Dim MyConnectionString as String =
ConfigurationSettings.AppSettings("ConnectionStrin g")

dim commInsert = Server.CreateObject("ADODB.Connection")
dim rsnewID = Server.CreateObject("ADODB.recordset")
commInsert.Open(MyConnectionString) ' Replace with your OLE DB
connection string.
commInsert.Execute("INSERT INTO tbl_contents (contenttypeID,
contentEN, contentFR, contentNL, contentDU, contentdescriptionEN,
contentdescriptionFR, contentdescriptionNL, contentdescriptionDU,
contentavailable, contentorder) VALUES('" &
ctype(contenttypeID.selecteditem.value,integer) & "','" &
contentEN.text & "','" & contentFR.text & "','" & contentNL.text &
"','" & contentDU.text & "','" & contentdescriptionEN.text & "','" &
contentdescriptionFR.text & "','" & contentdescriptionNL.text & "','"
& contentdescriptionDU.text & "'," & contentavailable.checked & ",'"
& contentorder.text & "');")

rsNewID = commInsert.Execute("SELECT @@IDENTITY ")
dim intNewID = rsNewID(0).value
rsNewID.Close
rsNewID = Nothing
commInsert.Close
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 CommandParameter:
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
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...
2
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...
5
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: ...
14
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...
0
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...
1
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....
1
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...
6
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...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.