Tuesday, September 20, 2011

Reading and Writing CLOB column in oracle by asp.net


Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types

Public Sub ReadLOBData()
Dim con As New OracleConnection(connectionstring)
con.Open()
Dim sql As String = "Select Mft_Text from Tab_Manifestation where Mft_Id=2"
Dim cmd As OracleCommand = New OracleCommand(sql, con)
Dim dr As OracleDataReader = cmd.ExecuteReader()
dr.Read()
Dim blob As OracleClob = dr.GetOracleClob(0)
txtManifest.Text = blob.Value
blob.Close()
dr.Close()
con.Close()
End Sub

Public Sub WriteLOBData()
Dim connection As New OracleConnection(connectionstring)
connection.Open()

Dim strSQL As String = "INSERT INTO TestCLOB (ID,CLOBTEXTFIELD) VALUES (1,:TEXT_DATA) "
'Dim strsql As String = "UPDATE TestCLOB SET CLOBTEXTFIELD=:TEXTDATA where testid=1"
Dim paramData As New OracleParameter
paramData.Direction = ParameterDirection.Input
paramData.OracleDbType = OracleDbType.Clob
paramData.ParameterName = "TEXT_DATA"
paramData.Value = txtInput.Text

Dim cmd As New OracleCommand
cmd.Connection = connection
cmd.Parameters.Add(paramData)
cmd.CommandText = strSQL
cmd.ExecuteNonQuery()

paramData = Nothing
cmd = Nothing
connection.Close()
End Sub

Monday, March 7, 2011

Parent Child Relation Query in Oracle

This query brings the records where record is related with parent
records

select parent
from relation
start with child='d2'
connect by prior parent = child;

Thursday, March 18, 2010

Keeping Session Live all the time in Asp.net

In Master Page of Page Load Event Call the Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load AddKeepAlive()
End Sub
Private Sub AddKeepAlive() Dim int_MilliSecondsTimeOut As Integer = 2 * 60 * 1000 '2 minutes 'Math.Max((this.Session.Timeout * 60000) - 30000, 5000); Dim path As String = VirtualPathUtility.ToAbsolute("~/KeepAlive.aspx")
Dim str_Script As String = ("<script>(function(){var r=0,w=window;if (w.setInterval)w.setInterval(function() {r ;var img=new Image(1,1);img.src='" & path & "?count=' r;},") int_MilliSecondsTimeOut.ToString() & ");})();</script>" Page.ClientScript.RegisterStartupScript(GetType(Page), UniqueID & "Reconnect", str_Script) End Sub


Create a Page say as KeepAlive.aspx
Add this in the Page

<%@ OutputCache Location="None" VaryByParam="None" %><?xml version="1.0" encoding="utf-8"?>
<%=now %>

Monday, February 22, 2010

To Fire OnBlur Event of Textbox on Sever Side

I will show in this post a simple method to fire onBlur Event of a textbox in server side, this can be used to check the value in textbox with the database, like to validate the data if already exist

put a server side button in the page and hide the button with div having style display none so that it is not triggered by clicking event
In page load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim eventhandler As String = Me.ClientScript.GetPostBackEventReference(Me.btnLoad, "")
Me.TextName.Attributes.Add("onblur", eventhandler)

End Sub


Write your process in the button click event
Protected Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click
‘Put your Own Code’
End Sub

Thursday, February 18, 2010

Enter Key in Asp.net

One of the common requests in ASP.NET is to submit a form when visitor hits an Enter key. That could be a case if, for example you want to make Login Screen. It is expected that user just hit enter when he insert a user name and password instead to of forcing him to use a mouse to click login button. If you want to make search function on your web site, it is frequently required to give a possibility to hit enter after you insert a search terms instead of mouse click on a Search button.

When you don’t want to submit a form with Enter key?

Rarely, you will need to disable an Enter key and avoid submitting form. If you want to prevent it completely, you need to use OnKeyDown handler on <body> tag of your page. The JavaScript code should be:


if (window.event.keyCode == 13)
{
event.returnValue=false;
event.cancel = true;
}



How to make a default button in ASP.NET
Method1:

TextBox1.Attributes.Add("onkeydown", "if(event.which event.keyCode){if ((event.which == 13) (event.keyCode == 13)) {document.getElementById('"+Button1.UniqueID+"').click();return false;}} else {return true}; ");

Method2:

<form defaultbutton="button1" runat="server">
<asp:textbox id="textbox1" runat="server"/>
<asp:textbox id="textbox2" runat="server"/>
<asp:button id="button1" text="Button1" runat="server"/>

<asp:panel defaultbutton="button2" runat="server">
<asp:textbox id="textbox3" runat="server"/>
<asp:button id="button2" runat="server"/>
</asp:panel>
</form>

Sunday, February 7, 2010

Replace any Character in Text File in Vb.net

Sub Main()
Dim Fs As FileStream = New FileStream("c:\Edit1.TXT",FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim sw As New StreamWriter(Fs)
Dim sr As New StreamReader(Fs)
Dim str As String
str = sr.ReadToEnd()
str = str.Replace(vbCrLf, "^")
Fs.Position = 0
Fs.SetLength(str.Length)
sw.Write(str)
sw.Flush()
sw.Close()
Fs.Close()
End Sub

Happy Coding!

Sunday, January 17, 2010

SFTP Client OpenSource and DLL

You can find opensource code to for SecureFTP Server in the below said link
where the dlls can be used in .Net to access files in SecureFTP Server

http://www.tamirgal.com/blog/page/SharpSSH.aspx

Thanks to Tamir Gal

Note: In the wrapper class the rm function has to be called for remove file function in the source code and compile