Posted by malakablog on October 10, 2008
So I have a View that join different tables, I wanted to get the Table name of a Field in the View. So I created a Function [GetTableName] with the following Inputs
- View Name
- Connection String of the View.
- The required Field Name
This is the function
public string GetTableName (string ViewName, string ConnString, string FieldName)
{
SqlConnection MyConnection;
string toReturn = ViewName;
MyConnection = new SqlConnection(ConnString);
MyConnection.Open();
DataTable MyTable = MyConnection.GetSchema(“Views”);
foreach (DataRow dRow in MyTable.Rows)
{
object[] sqlArray = dRow.ItemArray;
if (sqlArray.GetValue(2).ToString() == ViewName)
{
DataTable MyVTable = MyConnection.GetSchema(“ViewColumns”);
foreach (DataRow dVRow in MyVTable.Rows)
{
object[] sqlVArray = dVRow.ItemArray;
if (sqlVArray.GetValue(2).ToString() == ViewName)
{
if (sqlVArray.GetValue(6).ToString() == FieldName)
{
toReturn = sqlVArray[5].ToString();
}
}
}
}
}
return toReturn;
}
Posted in Uncategorized | Tagged: application, beginner, C#, code, Connection, Database, development, Field, Function, SQL 2000, Table, View, VS2005, Web.Services, WebMethods | Leave a Comment »
Posted by malakablog on October 8, 2008
I created functions for updateing/reading sessions variables using PageMthods and WebMethods, I am using VS2005 (VB.NET):
Import the web.services library
Imports System.Web.Services
This is the VB.NET function for setting the session variables
<WebMethod()> _
Public Shared Function AjaxSetSession(ByVal SessionValue As String)
Try
HttpContext.Current.Session(“SessionKey”) = SessionValue
Catch ex As Exception
End Try
End Function
To access the session we need to use HttpContext.Current.Session
This is the VB.NET function for getting the session variables
<WebMethod()> _
Public Shared Function AjaxGetSession() As String
Try
AjaxGetSession = HttpContext.Current.Session(“SessionKey”)
Catch ex As Exception
AjaxGetSession = “Error”
End Try
End Function
This is the JavaScript Code to set the session variable
PageMethods.AjaxSetSession(“PageMethods”,”WebMethods”)
This the JavaScript Code to read the Session Variables
PageMethods.AjaxGetSession(JSGetSessionSucess,JSGetSessionFaild);
JSGetSessionSucess is a JavaScript function that would be executed if the AjaxGetSession succeeded
function JSGetSessionSucess(value, methodName)
{
try
{
alert(value);
}
catch(err)
{
}
finally
{
}
}
JSGetSessionFaild is a JavaScript function that would be executed if the AjaxGetSession failed
function JSGetSessionFaild (ex, methodName)
{
try
{
alert(ex.get_exceptionType());
}
catch(err)
{
}
finally
{
}
}
Posted in Uncategorized | Tagged: AJAX, AJAX.NET, application, beginner, code, development, HTML, JavaScript, PageMethods, Programming, Session, VB.NET, VS2005, Web.Services, WebMethods | Leave a Comment »