tag:blogger.com,1999:blog-72321504158729260622024-03-08T15:07:56.109+02:00Amr SaafanThink outside the box...Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.comBlogger96125tag:blogger.com,1999:blog-7232150415872926062.post-47885759153008781592016-07-13T20:06:00.003+02:002021-09-08T14:30:12.651+02:00SQL Server 2012 Auto Identity Column Value Jump bug!
I am working on a database using SQL Server 2012. There is a table named Order has an auto Identity Column named OrderId datatype is int .
I noticed that the sequence of the identity is just not right. It has jumped with 1000.
After research about this issue, I found that this is an issue with SQL Server 2012 version.
From SQL Server 2012 version, when SQL Server Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-35819504056921806912015-01-01T15:01:00.001+02:002020-11-04T11:21:56.746+02:00How to migrate a domain without losing your SEO
1. Map All Old Domain URLs To Their New Domain Versions
This basically required mapping all of the dynamic and static old domain URLs to new domain URLs so they could all be 301 redirected at launch.
2. Understand How Any UI Changes Might Affect SEO
Changing UI while changing domains should be avoided whenever possible to eliminate yet another thing that could go wrong. That Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-42846194403511348502014-02-01T17:23:00.001+02:002020-11-04T11:11:00.763+02:00 Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack ASP.NET
While I was debugging an ASP.NET Application, I wanted to get an object values I got this error message instead:
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
This problem occurs when using Response.Redirect or Server.Transfer method, because the Response.End method ends the page execution and shifts the execution to the Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-82980790655640962072013-08-23T23:05:00.001+02:002020-11-03T17:49:39.246+02:00Adding the specified count to the semaphore would cause it to exceed its maximum count
I got this unusual exception while working on an ASP.NET project:
"Adding the specified count to the semaphore would cause it to exceed its maximum count error".
I thought it is something related to SQL Server Database Connection String.
After using Query Profiler I was able to run SQL queries directly without any problems.
So this means that the issue in ASP.NET Application not with the SQL Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-79211612109172399132013-07-11T22:11:00.001+02:002020-11-03T11:47:34.387+02:00How to disable some context menu items on Telerik TreeView
There is an event named "OnClientContextMenuShowing" for Rad Treeview that calls javascipt function and passes 2 arguments "sender, args".
The Args parameter contains The current selected TreeNode and Context Menu Items.
You can enable or disable any Context menu item based on any attributes for the Current Selected Tree Node.
Here is a code snippet for the javascript function that demonstrate Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-32535149459260600052013-05-01T18:38:00.001+02:002020-11-02T21:24:59.322+02:00How to Select from Data Table in C#
DataTable Object has a Select Method which acts like Where in SQL Server. So if you want to write filter query you write the column name directly without Where and the filter expression you want.
I made a simple example that creates a DataTable and fill it with some data and use Select method:
DataTable dt = new DataTable("MyDataTable");
dt.Columns.Add(new DataColumn("ID", typeof(int)));
Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-56349954673616986022013-03-01T13:26:00.001+02:002020-11-01T13:46:23.049+02:00How to get Year, Month and Day out of SQL Date in SQL Server
Let is say that we have the following Date 2007-04-05 10:13:14.109 and we want to get Year, Month and Day out of this date.
There is a function named DATEPART() that can be used to archive this.
DECLARE @MyDate AS DATETIME
SET @MyDate = '2007-04-05 10:13:14.109'
SELECT DATEPART(DAY, @MyDate) AS MyDay, DATEPART(MONTH, @MyDate) AS MyMonth, DATEPART(YEAR, @MyDate) AS MyYear
The resultAmr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-52802637919277428022013-02-01T01:55:00.001+02:002020-11-01T11:15:38.733+02:00How to know if a Date is in range between two Dates in C#
Let's say that we have a DateTime = Jan 1, 2012 and we want to check if this date is between 2 other dates.
The following code example Implements IRange interface that can be used with Integers too.
public interface IRange
{
T Start { get; }
T End { get; }
bool WithInRange(T value);
bool WithInRange(IRange range);
}
public class DateRange : IRange
Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-27445611142658251952013-01-01T11:01:00.001+02:002020-11-01T09:27:14.368+02:00How to avoid Uncaught ReferenceError: $ is not defined in jQuery
Sometimes while developing an existing Web Application, I wanted to use jQuery function and I get this error "Uncaught ReferenceError: $ is not defined".
There are some reasons causing it and ways to avoid them:
Make sure the references to the jQuery scripts is loading first, but them in the head of master page or the page you are using.
Sometimes the references to theAmr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-86713539647984817862012-06-01T21:56:00.001+02:002020-10-31T19:06:42.838+02:00How to Replace the First Instance of a String in C#
Assume that you have a string and you expect that this string might have some duplicated instances.
String.Replace() is very good Function, but it will replace all the instances of the string. So to accomplish this you need to replace the first instance you find.
The next code example can be used as a helper method in your project if you are dealing with strings frequently:
public static Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-71923860046013962422012-05-01T19:26:00.001+02:002020-10-31T14:29:28.556+02:00How to Programmatically create iFrame in ASP.NET
Sometimes we may need to create iFrames and use it within GridView or Repeater, and we want to pass some values to it.
This example will show you how to create iFrame Programmatically and add it to a PlaceHolder.
HtmlGenericControl myFrame = new HtmlGenericControl();
myFrame.TagName = "IFRAME";
myFrame.Attributes["src"] = "MyPagePath";
myFrame.Attributes["id"] = "myFrame1";
Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-65284896881524314592012-04-23T15:51:00.001+02:002020-10-31T14:14:36.827+02:00Operation is not valid due to the current state of the object, Exception in ASP.NET
I got this error when I tried to save a Page with lots of form fields to SQL Server Database.
The default max number of form fields that can be post is 1000.
In order to solve this error add this Line to your Web.Config File:
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="10000" />
</appSettings>
Source: https://www.nilebits.com/blog/Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-34342245117015400492012-03-01T17:54:00.001+02:002020-10-31T14:04:00.134+02:00How to Convert SqlDataSource to DataTable and DataView in C#
Sometimes I want to use SqlDataSource returned data programmatically and here is how you can do this,
In this example I will assume that SqlDataSource ID is SqlDataSource1 which is the default ID:
DataSourceSelectArguments args = new DataSourceSelectArguments();
DataView view = SqlDataSource1.Select(args) as DataView;
DataTable dt = view.ToTable();
Source: https://Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-37398654506694348322012-02-15T23:54:00.001+02:002020-10-30T23:41:32.119+02:00How to Submit a Form Using JavaScript
Any form is submitted when the user click on the submit button.
But you may need to submit the form programmatically using JavaScript.
JavaScript has the form object that contains the submit() method.
Use the "ID" of the form to get the form object.
Example:
If the name of the form is "Form1", JavaScript code for the submit method is:
document.forms["Form1"].submit();
Source: https://Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-10535653724233016002012-01-01T15:57:00.001+02:002020-10-30T23:30:50.115+02:00Javascript Regular Expression to match a comma delimited list
This method uses the JavaScript String's match() method to parse a comma delimited list and show its content in a Panel control.
You can try it here http://jsfiddle.net/38tXU/
function parseList(list) {
var reg = list.match(/\w+(,\w+)*/g);
document.getElementById('pnl').innerHTML = 'Total length:' + reg.length + '<br />';
for (var i = 0; i < reg.length; i++) {
Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-14419382862378519132011-11-09T00:47:00.000+02:002018-10-15T12:53:45.349+02:00How to Completely Disable Viewstate in ASP.NET
I tried to disable Viewstate of a website by set EnableViewState Page directive to false.
But when I get the Page HTML Source I found the following line:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUKMTY1NDU2MTA1MmRk7eWz8DBE7zF7MW8sS4wNndKCr5gBJPZZ/LOS1KIbBo4=" />
protected override void SavePageStateToPersistenceMedium(Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-33058913721789189392011-11-01T12:19:00.001+02:002020-10-30T23:01:38.645+02:00Difference between Inner and Outer Join in SQL
Joins are used to combine the data from two tables, with the result being a new, temporary table.
The temporary table is created based on column(s) that the two tables share, which represent meaningful column(s) of comparison.
The goal is to extract meaningful data from the resulting temporary table.
Joins are performed based on something called a predicate, which specifies the condition to use Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-5064559163740846972011-10-19T01:04:00.001+02:002020-10-30T22:52:42.221+02:00How to Copy some rows from a GridView to another in ASP.NET
A junior developer asked me can I select some rows from a GridView and copy them to another GridView?
I told him sure all you have to do is to create a DataTable and the columns that will be added to it.
Now you will loop for each row in the first GridView then add the selected rows to the DataTable.
Set the DataSource of the other GirdView to DataTable.
Here is the code that would do the trickAmr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-28073574044713613812011-10-03T14:48:00.001+02:002020-10-30T19:33:31.888+02:00Two Databound Fields in Gridview column
Boundfields are great in the Gridview, but they do have their limitations.
One is that it only has room for one bound field. So, what do you do when you want two or data fields.
For example, First and Last names returned to the same column.
Turn the BoundField into a TemplateField, with a label in it:
<asp:templatefield>
<itemtemplate>
<asp:label id="Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com2tag:blogger.com,1999:blog-7232150415872926062.post-36224802620904055572011-09-01T19:28:00.001+02:002020-10-30T19:16:20.491+02:00Select Drop Down List Item After Declarative Databinding
The new declarative controls of ASP.NET 2.0 are really great. However, there are some times, when it may not seem so.
Let's say you have a DropDownList which is bound by a DataSource control. Also, you have other pages hitting this page, with querystrings, and based on the item in the querystring, you'd like the to select that item.
In ASP.NET 1.1, you'd just code it, and select it after the Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-59242434817911173932011-01-01T01:30:00.001+02:002020-10-30T16:06:13.215+02:00How to check SQL Server Database is Exists using C#
The following method using sys. schema and views such as sys.databases and sys.tables.
As we know that the old style sysobjects and sysdatabases and those catalog views have been deprecated since SQL Server 2005.
private static bool CheckDatabaseExists(string connectionString, string databaseName)
{
string sqlQuery;
bool result = false;
try
{
Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-64833534914436295602010-07-01T11:32:00.001+03:002020-10-30T15:58:25.362+02:00How to get Drop Down List Selected Text in ASP .NET by using jQuery
The Following code sample shows how to get selected text out from ASP .NET Drop Down List.
<script type="text/javascript">
function GetSelectedText() {
var ddlID = '#' + '<%= ddlEmployees.ClientID %>';
var selectedText = $(ddlID + " option:selected").text();
return selectedText;
}
</script>
<asp:DropDownList ID="Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-90767454558498689832010-06-01T23:27:00.001+03:002020-10-30T15:38:58.869+02:00How to Dynamically Select rows in SQL Server
If you want to restrict other developers from using your Stored Procedures that returns a huge amount of data which affects server performance and Application Performance weather it is a Windows or Web Application.
You can use the following idea when you create Stored Procedures:
-- =============================================
-- Author: Amr Saafan
-- Create date: Jan 5, 2010
-- Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-53730867534368657232010-05-01T23:40:00.001+03:002020-10-28T17:51:40.250+02:00How to convert Data Row to Data Row View
Converting Data Row to Data Row View is not possible, but we can go around this by using DefaultView property of the Data Row Table.
The following code example demonstrate how to get Data Row View out of Data Row:
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
for (int i = 0; i < 10; i++)
{
DataRow tempDR = dt.NewRow();
tempDR["ID"Amr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0tag:blogger.com,1999:blog-7232150415872926062.post-54254571426070873872010-04-01T16:15:00.001+02:002020-10-28T14:57:34.733+02:00Prevent Saving Changes That Require Table Re-creation SQL Server 2008
I was modifying an existing table using SQL Server Management Studio 2008 R2, but I got this error message on saving:
Saving changes is not permitted. The changes that you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.
ThisAmr Saafanhttp://www.blogger.com/profile/07434802167262444653noreply@blogger.com0