Public Function GetAlphabeticString(ByVal pStrText As String, ByVal pCharCase As TextCases, ByVal pLength As Integer) As String
If pLength > 0 Then pStrText = trimString(pStrText, pLength)
Return GetAlphabeticString(pStrText, pCharCase)
End Function
Public Function GetAlphabeticString(ByVal pStrText As String, ByVal pCharCase As TextCases) As String
Select Case pCharCase
Case TextCases.Upper : mPattern = "^([A-Z]+)$"
Case TextCases.Lower : mPattern = "^([a-z]+)$"
Case TextCases.Both : mPattern = "^([A-Za-z]+)$"
End Select
If Regex.IsMatch(pStrText, mPattern) Then : Return pStrText
Else : Return ""
End If
End Function
Public Function GetAlphanumericString(ByVal pStrText As String, ByVal pCharCase As TextCases, ByVal pLength As Integer) As String
If pLength > 0 Then pStrText = trimString(pStrText, pLength)
Return GetAlphanumericString(pStrText, pCharCase)
End Function
Public Function GetAlphanumericString(ByVal pStrText As String, ByVal pCharCase As TextCases) As String
Select Case pCharCase
Case TextCases.Upper : mPattern = "^([A-Z0-9]+)$"
Case TextCases.Lower : mPattern = "^([a-z0-9]+)$"
Case TextCases.Both : mPattern = "^([A-Za-z0-9]+)$"
End Select
If Regex.IsMatch(pStrText, mPattern) Then : Return pStrText
Else : Return ""
End If
End Function
Public Function GetSessionVar(ByVal pASPSessionVar As String) As String
Dim pASPCookieName As String
Dim pASPCookieValue As String
If Not GetSessionCookie(pASPCookieName, pASPCookieValue) Then
Return ""
End If
Dim pMyRequest As HttpWebRequest = CType(WebRequest.Create(mASPSessionVarASP + "?SessionVar=" + pASPSessionVar), HttpWebRequest)
pMyRequest.Headers.Add("Cookie: " + pASPCookieName + "=" + pASPCookieValue)
'pMyRequest.RequestUri()
'pMyRequest.Timeout = 10000
'pMyRequest.KeepAlive = False
'pMyRequest.Method = "POST"
Dim pMyResponse As HttpWebResponse = CType(pMyRequest.GetResponse(), HttpWebResponse)
Dim pReceiveStream As Stream = pMyResponse.GetResponseStream()
Dim pReadStream As StreamReader = New StreamReader(pReceiveStream, System.Text.Encoding.UTF8)
Dim pStrResponse As String = pReadStream.ReadToEnd()
pReadStream.Close()
pMyResponse.Close()
Return pStrResponse
End Function
Private Function GetSessionCookie(ByRef pASPCookieName As String, ByRef pASPCookieVal As String) As Boolean
Dim pIntCnt As Integer
Dim pMyCookie As HttpCookie
pASPCookieName = ""
pASPCookieVal = ""
Dim pCookieArray As String() = mOcontext.Request.Cookies.AllKeys
For pIntCnt = 0 To pCookieArray.Length - 1
pMyCookie = mOcontext.Request.Cookies(pCookieArray.GetValue(pIntCnt))
If pMyCookie.Name.StartsWith("ASPSESSION") Then
pASPCookieName = pMyCookie.Name
pASPCookieVal = pMyCookie.Value
Return True
End If
Next
Return False
End Function
One of the interesting new features in Visual studio 2010 is that Microsoft has rewritten the code editor, and it's now 100% Windows Presentation Foundation (WPF). Because of this, they were able to add some exciting new features to the editor that otherwise might not have existed (or, at best, would have been a royal pain for Microsoft to add). Check out Julia's blog this week as she has put together a quick little video demonstrating the zoom feature. While zoom alone might not seem like a huge feature, what she's really demonstrating here is the power that comes with the editor being created under WPF. Will this give you some ideas for your own WPF programs? Maybe so!
Also this week we have an announcement regarding ASP.NET MVC V2. Microsoft has released a preview of Version 2. Thanks to the MFC (Model-View-Controller) architecture, creating scalable ASP.NET applications has gotten both easier and more intuitive. Now Microsoft is getting ready to release version 2, and has made available a preview of this newest version. We'll be exploring it here on DevSource; meanwhile you can check out what Darryl Taft has discovered about this update.
This is code to insert Grid details in vb.net you can use this function in common class.
you also need to declare required variable globally.
public Boolean InsertGridDetails(ref DataTable dt, string TableName, String PkValue, string PkName,SqlTransaction SqlTrans,SqlConnection Cn)
{
try
{
string query = "";
query = "select * from " + TableName + " where " + PkName + " = '" + PkValue + "'";
cmd = new SqlCommand(query, Cn);
cmd.Transaction = SqlTrans;
DA = new SqlDataAdapter(cmd);
SqlCommandBuilder GridDetail = new SqlCommandBuilder(DA);
DA.Update(dt);
return true;
}
catch
{
return false;
}
finally
{
cmd.Dispose();
DA.Dispose();
}
}
this is simple example to open and close connection in .net just use it with out hesitation and do not forget to include required name space like
using System;
using System.Data.SqlClient;
using System.Data;
namespace Common
{
public class Common
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connection"]);
public SqlConnection opendb()
{
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
else
{
con.Close();
con.Dispose();
con.Open();
}
return con;
}
catch
{
}
}
public SqlConnection closedb()
{
try
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
return con;
}
catch
{
}
}
}
}