Friday, September 30, 2011

Calling Javascript Value in asp.net Textbox

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>





Untitled Page













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

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnJSValue_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnJSValue.Click
txtJSValue.Text = inpHide.Value
End Sub

End Class

Row Number Generator in SQL Server

SELECT row_number() over (ORDER BY donorid) as SLNo, *
FROM BloodDonorDB.dbo.DonorData

Tuesday, August 2, 2011

Drop Shadow in CSS

.Example_E {
-moz-box-shadow: 0 0 10px #999;
-webkit-box-shadow: 0 0 10px#999;
box-shadow: 0 0 10px #999;
}

Monday, July 25, 2011

Using google map in asp.net

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>




















Passing value in formula field in crystal report

objRpt.DataDefinition.FormulaFields.Item("Location").Text = "'" & Application.StartupPath & "\IDCard1.jpg" & "'"
objRpt.Section3.ReportObjects("Picture2").Width = 850
objRpt.Section3.ReportObjects("Picture2").Height = 560

Saturday, July 16, 2011

Date field formatting in asp.net

select convert(varchar(10),RecDate,1) as [dd/MM/yy] from abc

where RecDate is name of field

Friday, July 15, 2011

Display alert before redirect in asp.net

ScriptManager.RegisterStartupScript(Me, Me.GetType(), "message", "alert('Thank for posting your comment. You will now be redirected to our home page.');location.href = 'EntryMaster.aspx'", True)

Thursday, July 14, 2011

Hide button after print javascript code

onclick="javascript:this.style.visibility='hidden';window.print();" class="ButtonGray" />

Print table in asp.net



Print only table in asp.net



Tuesday, May 3, 2011

Import Excel File in Access

[C#]
string Access = Server.MapPath("App_Data/contacts.mdb");
string Excel = Server.MapPath("App_Data/Book1.xls");
string connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Excel +";Extended Properties=Excel 8.0;";
using (OleDbConnection conn = new OleDbConnection(connect))
{
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO [MS Access;Database=" + Access + "].[Persons] SELECT * FROM [Sheet1$]";
conn.Open();
cmd.ExecuteNonQuery();
}
}
[VB]
Dim Access As String = Server.MapPath("App_Data/contacts.mdb")
Dim Excel As String = Server.MapPath("App_Data/Book1.xls")
Dim connect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Excel & _
";Extended Properties=Excel 8.0;"
Using conn As New OleDbConnection(connect)
Using cmd As New OleDbCommand()
cmd.Connection = conn
cmd.CommandText = "INSERT INTO [MS Access;Database=" & Access & "].[Persons] SELECT * FROM [Sheet1$]"
conn.Open()
cmd.ExecuteNonQuery()
End Using
End Using


Creating a new Table

A slight alteration to the SQL will result in a new table being created in the Access database, into which the records will be copied, along with the header row as field names:
[C#]
string Access = Server.MapPath("App_Data/contacts.mdb");
string Excel = Server.MapPath("App_Data/Book1.xls");
string connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Excel +";Extended Properties=Excel 8.0;";
using (OleDbConnection conn = new OleDbConnection(connect))
{
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = "SELECT * INTO [MS Access;Database=" + Access + "].[New Table] FROM [Sheet1$]";
conn.Open();
cmd.ExecuteNonQuery();
}
}
[VB]
Dim Access As String = Server.MapPath("App_Data/contacts.mdb")
Dim Excel As String = Server.MapPath("App_Data/Book1.xls")
Dim connect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Excel & _
";Extended Properties=Excel 8.0;"
Using conn As New OleDbConnection(connect)
Using cmd As New OleDbCommand()
cmd.Connection = conn
cmd.CommandText = "SELECT * INTO [MS Access;Database=" & Access & "].[New Table] FROM [Sheet1$]"
conn.Open()
cmd.ExecuteNonQuery()
End Using
End Using

Monday, January 17, 2011

Password Encyption and Decryption

Imports System
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
Inherits System.Web.UI.Page
Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}
Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219}

Dim CCNumber() As Byte
Dim DCNumber As String
Dim strConn As String
Dim Conn As SqlConnection
Dim strSQL As String


Public Function Encrypt(ByVal plainText As String) As Byte()
Dim utf8encoder As UTF8Encoding = New UTF8Encoding()
Dim inputInBytes() As Byte = utf8encoder.GetBytes(plainText)

Dim tdesProvider As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider()

Dim cryptoTransform As ICryptoTransform = tdesProvider.CreateEncryptor(Me.key, Me.iv)

Dim encryptedStream As MemoryStream = New MemoryStream()
Dim cryptStream As CryptoStream = New CryptoStream(encryptedStream, cryptoTransform, CryptoStreamMode.Write)

cryptStream.Write(inputInBytes, 0, inputInBytes.Length)
cryptStream.FlushFinalBlock()
encryptedStream.Position = 0

Dim result(encryptedStream.Length - 1) As Byte
encryptedStream.Read(result, 0, encryptedStream.Length)
cryptStream.Close()
Return result
End Function

Public Function Decrypt(ByVal inputInBytes() As Byte) As String
Dim utf8encoder As UTF8Encoding = New UTF8Encoding()
Dim tdesProvider As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider()

Dim cryptoTransform As ICryptoTransform = tdesProvider.CreateDecryptor(Me.key, Me.iv)

Dim decryptedStream As MemoryStream = New MemoryStream()
Dim cryptStream As CryptoStream = New CryptoStream(decryptedStream, cryptoTransform, CryptoStreamMode.Write)
cryptStream.Write(inputInBytes, 0, inputInBytes.Length)
cryptStream.FlushFinalBlock()
decryptedStream.Position = 0

Dim result(decryptedStream.Length - 1) As Byte
decryptedStream.Read(result, 0, decryptedStream.Length)
cryptStream.Close()
Dim myutf As UTF8Encoding = New UTF8Encoding()
Return myutf.GetString(result)
End Function

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
CCNumber = Encrypt(Me.TextBox1.Text)
OpenConnection()
Dim cmd As New SqlCommand("INSERT INTO MYLOGIN values (@UserID, @Password)", Conn)
cmd.CommandType = CommandType.Text
cmd.Parameters.Add("@UserID", SqlDbType.VarChar).Value = "demo"
cmd.Parameters.Add("@Password", SqlDbType.VarBinary).Value = CCNumber
cmd.ExecuteNonQuery()
CloseConnection()
Response.Write("")
Me.TextBox1.Text = ""
End Sub

Private Sub OpenConnection()
strConn = System.Configuration.ConfigurationManager.AppSettings("MyDBConnection")
Conn = New SqlConnection(strConn)
Conn.Open()
End Sub

Private Sub CloseConnection()
If Conn.State = ConnectionState.Open Then Conn.Close()
End Sub


Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
OpenConnection()
Dim cmd As SqlCommand = New SqlCommand("SELECT * from MyLogin", Conn)
Dim DA As SqlDataAdapter = New SqlDataAdapter()
DA.SelectCommand = cmd
Dim DS As DataSet = New DataSet()
DA.Fill(DS, "MyLogin")
GridView1.DataSource = DS
GridView1.DataBind()
Conn.Close()

For Each dr In DS.Tables("MyLogin").Rows
DCNumber = Decrypt(dr.Item("Password"))
Response.Write(dr.item("Userid") & " " & DCNumber & "
")
Next
End Sub

End Class