CoderBlog.NET
Tengiz Tutisani's blog.

 
Useful Links:
 
LanguageBox 
 
Language

 
SearchBox 
 
 
ArchiveBox 
 
Archive
<February 2012>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
 
CategoriesBox 
 
Categories
  ASP.NET (5)
  Ajax (1)
  C# (7)
  Common (1)
  HTML (3)
  JavaScript (5)
  Products (1)
  SEO (1)
  SQL (1)
  Visual Studio (1)
  Windows (1)
 
FriendSitesBox 
 
Friend Sites
  AdMoney Project
  Cайт о гитаре и музыке!
  Design Studio IMAGINE
 
CustomContentBox [1] 
 



 
 
How to dynamically include JavaScript script reference into html
JavaScript’s day
Posted By:   tengo
At:   5/14/2009 5:25:00 PM
 

One of my friends asked me how to dynamically include a reference to the JavaScript file into an html file.
Sincerely to say, I didn't know what to answer. But no additional effort was needed to find the answer, it's easy.
If you are familiar with JavaScript, then you can think of it yourself and you'll find the answer.

I wrote a function in JavaScript which makes all the work: dynamically creates object corresponding to the "<script>" tag, assigns it's "src" property a value of file name, and then adds this object to the current document. Have a look:

<script language="javascript" type="text/javascript">
function IncludeJS(file)
{
var scr = window.document.createElement("script");
scr.src = file;
document.body.appendChild(scr);
}
</script>


All works fine. One more thing I would mention here:
When invoking a method that is contained in dynamically referenced script file, always make a little more coding to ensure that no script errors will be thrown. For this purpose, my test button's "onclick" event checks, if the method that SHOULD be in the included file, exists. Look at this button tag:

<input type="button" value="Invoke Sample Method" onclick="if (window.SampleMethod) SampleMethod()" />

That's all about today's JavaScript.


Filed Under:   JavaScript | HTML |
Post Tags:   dynamically | file | function | html | include | javascript | js | script | src |
  Comments [0]



 
 
ExecuteScalar() result cannot be converted as expected
Strange results
Posted By:   tengo
At:   4/30/2009 9:55:00 AM
 

Colleague wrote a little method in C# code, where he created SqlCommand object and assigned to it's CommandText property as shown:

command1.CommandText = "select dbo.fn_GetValue(‘parameters')";

As you understood he tried to select a result of the database function. The function returns value of type bit. After invoking ExecuteScalar, command returned an object, which could not be converted to the bool type as expected. Strange!
As I saw execution returned value as a string with the exception that added an empty spaces in the end. So, I advise you to avoid using such kind of commands, use execution of stored procedures instead. In that case the result will be as expected.

BTW, I found some not very good solution of this problem also. Just change a command text as followed:

command1.CommandText = "select cast(dbo.fn_GetValue(‘parameters') as bit)";

Everything will work, but again, I would use stored procedure instead, and of course, in case of stored procedures, you must specify the correct CommandType property value of the SqlCommand object. The property value must be System.Data.CommandType.StoredProcedure instead of System.Data.CommandType.Text.

I recommend visiting MSDN library article which explains details of working with the SqlCommand object shipped with Microsoft .NET framework, in particular on how to Set and Get Parameters for Command Objects.

That's all for today.

Don't forget, to have a rest is as important as to make a good job.


Filed Under:   C# | SQL |
Post Tags:   csharp | execute | function | object | procedure | result | scalar | sql |
  Comments [0]



 
CustomContentBox [2] 
 
Useful Links:
 
CategoryViewBox 
 
CoderBlog.NET
  Get your own Blog Engine
  SMS Sending Service
  What do you want to see on CoderBlog.NET?
  IMAGINE.GE created a header image for CoderBlog.NET
  CoderBlog.NET offers link exchange
  Quick language selection added
  CoderBlog.NET ‘s what is what
  Welcome to CoderBlog.NET

  Jump to Category...
 
TagsBox 
 
Popular Tags
aspnetblogcsharpdesigndivengineerrorformhtmljavascript
 
AuthorsBox 
 
Authors
  Tengiz Tutisani  (25)
 
SubscriptionsBox 
 
Subscriptions
Your Email:
 
LoginStatusBox 
 
Site Members
Login
 
Copyright © 2009 . CoderBlog.NET