Monday, August 23, 2010
Saturday, August 21, 2010
<form action="http://www.google.com/cse" id="cse-search-box">
<div>
<input type="hidden" name="cx" value="partner-pub-3239228842410427:5ea2x3-35nv" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="text" name="q" size="31" />
<input type="submit" name="sa" value="Search" />
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
<div>
<input type="hidden" name="cx" value="partner-pub-3239228842410427:5ea2x3-35nv" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="text" name="q" size="31" />
<input type="submit" name="sa" value="Search" />
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
Tuesday, August 17, 2010
HTTPException was unhandled by User Code?
HTTPException was unhandled by User Code?
Error executing child request for ~/page.aspx.
Ans: if page.aspx not exists in your current directory or renamed, so check the name.
Error executing child request for ~/page.aspx.
Ans: if page.aspx not exists in your current directory or renamed, so check the name.
Microsoft JScript runtime error?
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '
<!DOCTYPE html P'.
Ans: Server.Transfer or Response.write wont work in Ajax enabled pages.
Details: Error parsing near '
<!DOCTYPE html P'.
Ans: Server.Transfer or Response.write wont work in Ajax enabled pages.
Thursday, August 12, 2010
Sample LINQ Queries
DBDataContext objeDC =new DBDataContext();
1. How to check whether the UserID exist in the table using LINQ?
4. use Transaction in LINQ (Roll and Commit)
ex.. Convert Datetime column (MM/dd/YYYY) to dd/MM/yyyy
13. convert LINQ Results to DataTable
12. Format the retrieve column using LINQ) 10. Delete a record using LINQ?9. Check the column value having specified characters using LINQ?8. Bind into gridview using LINQ?7. Bind into DropdownList using LINQ?6. Update Single value to particular record using LINQ 3. Encrpted Password2. insert Values into table using LINQ?
1. How to check whether the UserID exist in the table using LINQ?
UserMst objUserMst =null;
objUserMst= objeDC.UserMsts.SingleOrDefault(Rec => Rec.UserMstID == "sample");
if(objUserMst !=null)
//exists
else
// Not exists
PwdHistory objHistory = new PwdHistory();
objHistory.UserName = "Sample";
objHistory.UserPwd = FormsAuthentication.HashPasswordForStoringInConfigFile("password", "MD5");
objeDC.PwdHistories.InsertOnSubmit(objHistory);
objeDC.SubmitChanges();
FormsAuthentication.HashPasswordForStoringInConfigFile("password", "MD5");
DBTransaction objDBTrans=null;5. Simple where condition using LINQ
objDBTrans = objeDC.Connection.BeginTransaction();
objeDC.Transaction = objDBTrans ;
try
{
PwdHistory objHistory = new PwdHistory();
objHistory.UserName = "Sample";
objHistory.UserPwd = FormsAuthentication.HashPasswordForStoringInConfigFile("password", "MD5");
objeDC.PwdHistories.InsertOnSubmit(objHistory);
objeDC.SubmitChanges();
objDBTrans.Commit();
}
catch(Exception ex)
{
objDBTrans.RollBack();
}
var Result = from objLogin in objeDC.LoginLogs
where objLogin.UserMstID == strLoginId && objLogin.LoginEventID == "02"
select objLogin;
objUserMst = objeDC.UserMsts.SingleOrDefault(Rec => Rec.UserMstID == "sample");
if (objUserMst != null)
{
objUserMst.eInsInd = true;
objeDC.SubmitChanges();
}
var Result = from objUserGroup in objeDC.UserGroups
select objUserGroup;
DropdownList1.DataTextField = "Dsc";
DropdownList1.DataValueField = "UserGroupID";
DropdownList1.DataSource = Result;
DropdownList1.DataBind();
var Result = from objNewsMast in objeDC.NewsMasts
orderby objNewsMast.TimeStamp
select objNewsMast;
gvNewsImage.DataSource = Result;
gvNewsImage.DataBind();
var Result = from objMenu in objeDC.Menus
select new
{
MenuID = objMenu.MenuID.ToString().Contains(".aspx") == true?objMenu.MenuID :
string.Empty ,
Dsc = objMenu.Dsc,
};
11. Delete multiple records based on condition using LINQ?
UserGroups objUserGrp = null;
objUserGrp = objeDC.UserGroups.SingleOrDefault(Rec => Rec.UserGroupID == "stringval");
if (objUserGrp != null)
{
objeDC.UserGroups.DeleteOnSubmit(objUserGrp);
objeDC.SubmitChanges();
}
objeDC.MenuAccesses.DeleteAllOnSubmit(objeDC.MenuAccesses.Where(Tmpr => Tmpr.MenuID == strMenuID));
objeDC.SubmitChanges();
ex.. Convert Datetime column (MM/dd/YYYY) to dd/MM/yyyy
var objResult = from objTemp in
( from objNewsMast in objeDC.NewsMasts
select new
{
Date = objNewsMast.TimeStamp,
Title = objNewsMast.Title,
}).ToList()
select new
{
Date = objTemp.Date.ToString("dd/MM/yyyy"),
Title = objTemp.Title,
});
13. convert LINQ Results to DataTable
var ResultProgram = from objProgram in objeDC.Programs14. LINQ to DataTable
select objProgram;
DataTable dtProgram = LINQToDataTable(ResultProgram);
public DataTable LINQToDataTable<T>(IEnumerable<T> varlist)
{
DataTable dtReturn = new DataTable();
PropertyInfo[] oProps = null;
if (varlist == null) return dtReturn;
foreach (T rec in varlist)
{
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))
colType = colType.GetGenericArguments()[0];
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
DataRow dr = dtReturn.NewRow();
foreach (PropertyInfo pi in oProps)
{
dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue
(rec, null);
}
dtReturn.Rows.Add(dr);
}
return dtReturn;
}
12. Format the retrieve column using LINQ) 10. Delete a record using LINQ?9. Check the column value having specified characters using LINQ?8. Bind into gridview using LINQ?7. Bind into DropdownList using LINQ?6. Update Single value to particular record using LINQ 3. Encrpted Password2. insert Values into table using LINQ?
'Button1_Click' and no extension method 'Button1_Click' accepting a first argument of type 'ASP.feedback_aspx'
'ASP.feedback_aspx' does not contain a definition for 'Button1_Click' and no extension method 'Button1_Click' accepting a first argument of type 'ASP.feedback_aspx' could be found (are you missing a using directive or an assembly reference?)
Ans: After Delete the button and buttonl_Click event , it will thrown the above error while building because you didn't properly saved the file.
Save that file and rebuild the solution.
Ans: After Delete the button and buttonl_Click event , it will thrown the above error while building because you didn't properly saved the file.
Save that file and rebuild the solution.
Wednesday, August 11, 2010
Partitioning Operators
Partitioning Operators are
1. Take
2. Skip
3. TakeWhile
4. SkipWhile
Example SQL Table is UserMsts
Fields : UserMstID, Name, EMail, CreateBy, CreateDate , Address
1. Take Simple Query
2. Skip
3. Retrieve records from 10 - 20 for the following results
Records
var Result = from objUserMst in UserMsts
Output:
1235
1. Take
2. Skip
3. TakeWhile
4. SkipWhile
Example SQL Table is UserMsts
Fields : UserMstID, Name, EMail, CreateBy, CreateDate , Address
1. Take Simple Query
var Result = from objUserMst in UserMstsThis Query uses Take to get only the first 8 records.
select objUserMst;
foreach (var n in Result.Take(8))
Console.WriteLine (n.UserMstID + n.Name );
2. Skip
var Result = from objUserMst in UserMstsselect objUserMst;
foreach (var n in Result.Skip(3))This Query uses to SKIP first three record and retrieve rest of the records.
Console.WriteLine ("UserId="+n.UserMstID + "; Name = "+ n.Name );
3. Retrieve records from 10 - 20 for the following results
Records
Query:UserId=
UserId=admin
UserId=AZIZUL
UserId=D00281-000
UserId=D00304-000
UserId=D00611-000
UserId=D01619-000
UserId=D01745-000
UserId=D02669-000
UserId=D02670-0001
UserId=D02673-000
UserId=D02684-000
UserId=D02940-000
UserId=D03002-000
UserId=D03252-000
UserId=D06124-000
UserId=D09533-000
UserId=D09999-001
UserId=D10051-001
UserId=D10059-000
UserId=D11719-000
UserId=D12345-000
UserId=D99999-000
UserId=d99999-999
UserId=DAVID
UserId=Jason
UserId=mradmin
UserId=SOW
UserId=tech_it
UserId=TEST
UserId=test1
UserId=testing
UserId=Testing1
var Result = from objUserMst in UserMsts
Results:
select objUserMst;
foreach (var n in Result.Skip(10).Take(10))
Console.WriteLine ("UserId="+n.UserMstID );
UserId=D02673-0004. TakeWhile
UserId=D02684-000
UserId=D02940-000
UserId=D03002-000
UserId=D03252-000
UserId=D06124-000
UserId=D09533-000
UserId=D09999-001
UserId=D10051-001
UserId=D10059-000
int[] numArray = { 1235, 4456, 1234, 3232, 1900, 80000, 6234, 7123, 2343,0 };The above query TakeWhile to return elements starting from the beginning of the array whether the given(3232) number is hit and retrieved less than 3232 numbers from the array
var FindNumbers = numArray.TakeWhile(n => n < 3232);
foreach (var objFindNumbers in FindNumbers)
{
Console.WriteLine(objFindNumbers);
}
Output:
1235
Generate Password using C#
public string GeneratePassword()
{
{
Random rndNumber = null;char[] chars = null;
try}
{
int passwordLength = 8;
string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789";
chars = new char[passwordLength];
rndNumber = new Random();
for (int i = 0; i < passwordLength; i++)
{
chars[i] = allowedChars[rndNumber.Next(0, allowedChars.Length)];
}
}
catch
{
throw;
}
return new string(chars);
Subscribe to:
Posts (Atom)