Running Notes 5

                                                                     

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

2.
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
----------

c#
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.

Solution:
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

http://www.logiclabz.com/sql-server/split-function-in-sql-server-to-break-comma-separated-strings-into-table.aspx

-------------

sqserver

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

In Asp.net 

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 -->
</fieldset> 
</form>

<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.

--------------------------------------------------------

http://www.csharp-examples.net/string-format-double/
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

CREATE TABLE [Test] (
[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">
<columns>
  <asp :BoundField DataField="CreationDate"
     DataFormatString="{0:M-dd-yyyy}"
     HeaderText="CreationDate"   />
</columns>
</asp>

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">
<columns>
  <asp :BoundField DataField="CreationDate"
     DataFormatString="{0:M-dd-yyyy}"
     HtmlEncode="false"
     HeaderText="CreationDate"    />
</columns>
</asp>

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"  >
 <columns>
  <asp :TemplateField HeaderText="CreationDate" >
   <edititemtemplate>
    <asp :Label ID="Label1" runat="server"
      Text='<%# Eval("CreationDate", "{0:M-dd-yyyy}") %>'>
    </asp>
   </edititemtemplate>
   <itemtemplate>
    <asp :Label ID="Label1" runat="server"
      Text='<%# Bind("CreationDate", "{0:M-dd-yyyy}") %>'>
    </asp>
   </itemtemplate>
  </asp>
 </columns>
</asp>

========================

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)

---------------------------------------
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: