Connect database using javascript

Connect Sqlserver database using javascript

 

var connection = new ActiveXObject("ADODB.Connection") ;

var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;
User ID=<user>;Password=<password>;Provider=SQLOLEDB"
;

connection
.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");

rs
1.Open("SELECT * FROM table1", connection);
rs1
.MoveFirst
while(!rs1.eof)
{
   document
.write(rs1.fields(1));
   rs1
.movenext;
}

rs1
.close;
connection
.close;

 

--------------------------------------------------------------------------------

Connect access database using javascript

  1. <html>
  2.     <head>
  3.         <title>Entitled Document</title>
  4.         <script language="JavaScript">
  5.         function getCount(){
  6.             var cn = new ActiveXObject("ADODB.Connection");
  7.             var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;
  8. Data Source = C:\clientDB.mdb;Persist Security Info=False";
  9.             cn.Open(strConn);
  10.             var rs = new ActiveXObject("ADODB.Recordset");
  11.             var SQL = "select count(*) from Customers";
  12.             rs.Open(SQL, cn);
  13.             alert(rs(0));
  14.             rs.Close();
  15.             cn.Close(); 
  16.  
  17.         }
  18.         </script>
  19.     </head>
  20.     <body>
  21.         <input type="button" value="Get count" onclick="getCount()">
  22.     </body>
  23. </html>

 


Posted by: Admin
Posted on: 9/8/2010 at 6:41 PM
Tags: ,
Categories: Javascript
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Simple Chat using asp.net

Introduction
simplechat
     The best way is to use a nice database to store messages; however, for demo purposes, I'll use a static array. I hope, you won't be able to use it in your web form. Take this article as the concept, not as a solution. This simple web chat program is intended to work in any browser supporting

Get the code Replace this class if you are using a database to save the messages: public class Chat
{
static protected ArrayList permArray = new ArrayList();

static public void AddMessage(string sDealer, string sUser, string sMsg)
{
string sAddText = sDealer + "~" + sUser + "~" + sMsg;
permArray.Add(sAddText);
if ( permArray.Count > 200 )
{
permArray.RemoveRange(0,10);
}
}
static public string GetAllMessages(string sDealer)
{
string sResponse = "";
for (int i=0; i< permArray.Count; i++)
{
sResponse = sResponse + FormatChat(permArray[i].ToString(), sDealer);
}
return(sResponse);
}
static private string FormatChat(string sLine, string sDealer)
{
int iFirst = sLine.IndexOf("~");
int iLast = sLine.LastIndexOf("~");
string sDeal = sLine.Substring(0, iFirst);
if ( sDeal != sDealer)
return("");
string sUser = sLine.Substring(iFirst+1, iLast-(iFirst+1));
string sMsg = sLine.Substring(iLast+1);
string sRet = "" + sUser + ": " + sMsg + "";
return(sRet);
}
}

The above code reads and writes from the static array like in a database. The code only allows having 200 messages in the array, after that it deletes the top 10 at the time.
this is the code behind aspx.cs:
public class ChatWin : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TB_ToSend;
protected System.Web.UI.WebControls.Button BT_SendMsg;
private void Page_Load(object sender, System.EventArgs e)
{
if ( Page.IsPostBack == false )
{
if ( Request.Params["Channel"] != null )
Session["ChatChannel"] = Request.Params["Channel"].ToString();
else
Session["ChatChannel"] = "1";
}
}
#region Web Form Designer generated code override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.BT_SendMsg.Click += new System.EventHandler(this.BT_SendMsg_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

public string GetChatPage()
{
return("TheChatScreenWin.aspx");
}

private void BT_SendMsg_Click(object sender, System.EventArgs e)
{
string sChannel = "";
string sUser = "";
if ( Request.Params["Channel"] != null )
sChannel = Request.Params["Channel"].ToString();
else
sChannel = "1";
if ( Request.Params["User"] != null ) sUser = Request.Params["User"].ToString();
else
{
Random pRan = new Random();
int iNum = pRan.Next(9);
sUser = "Annonymouse" + iNum;
}
if ( TB_ToSend.Text.Length > 0)
{
PageModule.Chat.AddMessage(sChannel,sUser,TB_ToSend.Text);
TB_ToSend.Text = "";
}
}
}

Posted by: Admin
Posted on: 12/7/2009 at 1:26 PM
Tags: ,
Categories: chating
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (149) | Post RSSRSS comment feed

Count the Number of files in a Directory using asp.net

Count the Number of specified files in a Directory

Below is a function 'FilesDirectoryCount' that will count the number of files within a directory using The .NET Framework class Directory. The GetFiles method allows us to retrieve all the files with a '.jpg' file extension and we can then use the Length property to return the number of files.



Get Sample Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim FileCount As Integer = FilesDirectoryCount("C:\Inetpub\wwwroot\website1\images", ".gif")
If FileCount = 0 Then
lblFilesInDirectory.Text = "There are no gif files in the directory."
ElseIf FileCount = 1 Then
lblFilesInDirectory.Text = "There is 1 gif files in the directory." Else
lblFilesInDirectory.Text = "There are " & FilesDirectoryCount("H:\Inetpub\wwwroot\website1\images", "*.gif") & " gif files in the directory."
End If
End Sub



Function FilesDirectoryCount(ByVal myDirectory As String, ByVal Extension As String) As Integer
Return Directory.GetFiles(myDirectory, "*" & Extension).Length
End Function

Posted by: Admin
Posted on: 10/20/2009 at 5:46 PM
Tags: , , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (105) | Post RSSRSS comment feed

Unable to start debugging on the web server

Step 1. Open IIS Manager (Internbet Information Services)
Img: Control Panel

Img: IIS Wizard

Step 2. Right-click the website (in case you run it locally you only have Default web site) and pick Properties &
Img: Properties

Step 3. Choose "Directory Security" tab and click Edit on "Anonymous access and authentication control" 
Img: Directory Settings

Step 4. In the opening window, uncheck "Allow Anonymous access" and check "Integrated Windows Authentication" (allowing anonymous can make that you don't have enough permissions to debug) After that you also need to make sure your NT Debugger user is on Debugger users group (and in practise to attach to the aspnet_wp.exe process it also needs to be admin unless you change local security policies. Img: Authendication method

 


Posted by: Admin
Posted on: 10/8/2009 at 7:58 AM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (105) | Post RSSRSS comment feed

Unable to start debugging on the web server. Debugging failed because integrated Windows authentication is not enabled

1. Open IIS Manager (Internbet Information Services) 2. Right-click the website (in case you run it locally you only have Default web site) and pick Properties 3. Choose "Directory Security" tab and click Edit on "Anonymous access and authentication control" 4. In the opening window, uncheck "Allow Anonymous access" and check "Integrated Windows Authentication" (allowing anonymous can make that you don't have enough permissions to debug) After that you also need to make sure your NT Debugger user is on Debugger users group (and in practise to attach to the aspnet_wp.exe process it also needs to be admin unless you change local security policies


Posted by: Admin
Posted on: 10/8/2009 at 7:58 AM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (54) | Post RSSRSS comment feed