Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
enabling html code to be db compliant
Old 02-02-2006, 11:22 AM enabling html code to be db compliant
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
HI ,
Im creating html code string for saving to a database. An example of a strBody is shown below :

This is a test. Color check <font color="#ff6600">Orange </font><font color="#ff0000">Red </font><font color="#ffff00">Yellow </font>And then <strong>bold</strong>

My problem, is how to I write this to a database field. When I perform the update to table, the only data written in This is a test. Color check <font color=Any help on this would be much appreciated.

cheers
Steve
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 02-02-2006, 12:53 PM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
The problem looks like the quotes. What's your code like?
Personally, I use parameters to pass values to the database - that way you don't run into quoting problems and it also helps protect against SQL Injection attacks.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 02-02-2006, 02:41 PM
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
I can pass html in parameters though can I. Parameter s as I understand are fine with stored procedures. This is html code I want to store in a table and thus replicate later.

My code simply can be

strBody="This is a test. Color check <font color="#ff6600">Orange </font><font color="#ff0000">Red </font><font color="#ffff00">Yellow </font>And then <strong>bold</strong>"
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 02-03-2006, 06:38 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
SQL Parameters aren't restricted to Stored Procedures. I use them in SQL statement strings all the time. Not sure how they work in classic ASP, but this is an example of how I'd do it in .NET:

Code:
publicDataSet GetMessagesByDate(int UserID, DateTime MyDate)
{
string SQL = "SELECT Messages.Msg_ID, Messages.Msg_DateTime, Messages.Msg_Read, InternalUsers.User_FirstName, InternalUsers.User_LastName, ExternalUsers.User_ID, Messages.Msg_Message FROM (Messages INNER JOIN ExternalUsers ON Messages.Msg_MessageFor = ExternalUsers.User_ID) INNER JOIN InternalUsers ON Messages.Msg_AgentID = InternalUsers.User_ID WHERE ExternalUsers.User_ID = @MessageFor AND Messages.Msg_DateTime BETWEEN @DateTime AND @DateTime1 ORDER BY {0} {1}";
SqlParameter pSearchDate = newSqlParameter("@DateTime", SqlDbType.DateTime, 8);
pSearchDate.Value = MyDate;
SqlParameter pSearchDate1 = newSqlParameter("@DateTime1", SqlDbType.DateTime, 8);
pSearchDate1.Value = MyDate + newTimeSpan(23, 59, 59);
SqlParameter pMessageFor = newSqlParameter("@MessageFor", SqlDbType.Int, 4);
pMessageFor.Value = UserID;
returnSqlHelper.ExecuteDataset(
ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString,
CommandType.Text,
SQL,
pMessageFor, pSearchDate, pSearchDate1);
}


(The SqlHelper is a class provided by Microsoft for handling common SQL tasks. Internally, it would create a new SqlConnection object, and an SqlCommand object, then add the parameters to the SqlCommand's parameter list, then call the SqlCommand's ExecuteDataset() method)

I imagine the steps would be simular for ASP, just different syntax and objects.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Minaki; 02-03-2006 at 06:41 AM..
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 02-03-2006, 06:48 AM
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
im sorry but htis doesnt help at all. I understand all this even in .net.
MY problem is transfering physical html code to a field in a table. The problem will still arise if i put into a parameter as that doesnt deal with the double quote.
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 02-03-2006, 07:17 AM
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
ok i seem to have got over that. I think my problem was having servevr.htmencoded my strBody twice as I have a check form on the same page. This was confusing me as encoding twice gave weird results.
I have posted another post though becuase although i have written to the file, getting it out rendered seems not to be working.
cheers for your help though
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Reply     « Reply to enabling html code to be db compliant
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30687 seconds with 12 queries