Running Notes 5


1. Creating GUIDs with C#
 System.Guid guid=System.Guid.NewGuid();

isNumeric("42000", System.Globalization.NumberStyles.Integer)If you want to test for an integer number separated with commas, then do the following:

 Collapse Copy CodeisNumeric("42,000", System.Globalization.NumberStyles.Integer | 
	System.Globalization.NumberStyles.AllowThousands)Using Other Cultures

    (string val, System.Globalization.NumberStyles NumberStyle, string CultureName)
    Double result;
    return Double.TryParse(val,NumberStyle,new System.Globalization.CultureInfo
				(CultureName),out result);


sqlserver 2008 -> right click on database then : tasks -> generate scripts

convert Dataview to a DataTable in C#. All you have to use ToTable() Method of DataView objects


drop table #temp
create table #temp
(i int)
insert into #temp values(null)
--insert into #temp values(1)
--insert into #temp values(2)
--insert into #temp values(3)
select max(i) from #temp

sqlserver 2008

Problem :
Saving changes is not permitted. The changes 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.

Tools -> Options then go to the Designer Page and uncheck "Prevent saving changes that require table re-creation".


YOu cannot create a temporary tabe inside a function.
Functions always needs select dbo.functionname(par1) .. it is not select functionname(par1) ie dbo is required

Split a string sqlserver



in if else statemenet u cannot keep empty statements in the braces


for getting a rounded rectangle  use fieldset

<form id="form1" runat="server">
<fieldset style="width:140px"> 
<legend> User Login </legend> 
<!-- your Rest HTML control goes here -->

<Legend> tag is used to give the name to a group box.

After end of the <Legend> tag you can write any HTML tag like Table, Input etc.

String.Format("{0:0.0}", 0.0);            // "0.0"
String.Format("{0,-10:0.0}", 123.4567);   // "123.5     "
I have an identity column in a table which is autoincremented column.
I entered some 10 records,
I deleted those 10 records
WHen I tried to insert a new record it starts with 11
But my requirement is it should start with 1 

How to achieve this in Sqlserver?

Ans: Use truncate instead of delete
But I think one more way is also there which I dont know.

DROP table t (here t is table name): completely deletes all the records and it will drop the table also.
u will get object not exists error once u drop the table and using this select * from t

Truncate table t : deletes all the records and it wont drop the table.
so u can use select * from t even after truncating also.

in drop and truncate u cannot use where condition. It means u have lose the entire data in the table.
But in case of delete u can control the no. of records to be deleted.


Giving datetime default value during creation of table in Sqlserver

[Test_Creation_Date] [datetime] DEFAULT (getdate()) )


C#  check whether a string is integer or not 

public bool IsInteger(string data){	bool result = true;	try	{		int.Parse(data);	}	catch (FormatException)	{		result = false;	}return result;}


set date format in grid

<asp :GridView ID="GridView1" runat="server">
  <asp :BoundField DataField="CreationDate"
     HeaderText="CreationDate"   />

You have two choices to make this work as you would expect. The first choice is to simply set HtmlEncode to false as follows:

<asp :GridView ID="GridView1" runat="server">
  <asp :BoundField DataField="CreationDate"
     HeaderText="CreationDate"    />

The second choice is to make the column a template and simply set the format string directly in the Label or Text Fields as follows.

<asp :GridView ID="GridView3" runat="server"  >
  <asp :TemplateField HeaderText="CreationDate" >
    <asp :Label ID="Label1" runat="server"
      Text='<%# Eval("CreationDate", "{0:M-dd-yyyy}") %>'>
    <asp :Label ID="Label1" runat="server"
      Text='<%# Bind("CreationDate", "{0:M-dd-yyyy}") %>'>


System.Guid.NewGuid() in C# for new guid

geting the date part only in sqlserver
select CAST(FLOOR(CAST(getdate() AS DECIMAL(12, 5))) AS DATETIME)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: