How to use Asp
  • Home
  • About us
KEEP IN TOUCH

how to use isnull(), if, else if, while loop, return, select case in sql server

Apr21
2012
Leave a Comment Written by Vikram

– Here i m writing how can we use
–1. delay/timer
–2. goto
–3. isnull()
–4. select case
–5. while loop
–6. return
–7. if else
–8. if else if
– in sql server.

–1. using WAIT FOR
Select ‘Before Delay’ as [wait/delay]
WAITFOR DELAY ’00:00:05′ — will wait for 5 seconds
Select ‘After Delay’ as [wait/delay]

————–
–2. using How can we use go to statement
– using GOTO statement
GOTO a
select ‘not accessing’ as [goto]
a:
select ‘accessing call2′ as [goto]

——————
–3. using ISNULL
declare @a1 int
set @a1 = null
select ISNULL(@a1,0) as [isnull]

——————-
–4. using SELECT CASE
declare @a2 varchar(50)
set @a2 = ‘ok’
Select CASE
when @a2 = ‘true’
then ’1′
else ‘false’
end as [select case]

———————-
–5. using WHILE LOOP
declare @a3 int
set @a3=1
while(@a3 < =2)
begin
select @a3 as [While Loop]
set @a3 = @a3+1
end

—————–
–6. using return
declare @a4 int
set @a4=1
while(@a4 < =10)
begin
select @a4 as [return]
if (@a4 = 2)
return — you can use here GOTO also
set @a4 = @a4+1
end

—————–
–7. using if else
declare @a5 int
set @a5=1
if(@a5=1)
select ‘true’ as [if else]
else
select ‘false’ as [if else]

—————–
–8. using if elseif kind of select case statement.
declare @a6 int
set @a6=3
if(@a6=1)
select ‘true’ as [else if]
else if(@a6=2)
select ‘in else 1′ as [else if]
else if(@a6=3)
select ‘in else 2′ as [else if]
else
select ‘in else’ as [else if]

with regards

vik

Posted in Sql Server - Tagged else if, if else, isnull, return, select case, sql server, while loop

How to Upload and crop images with jquery in ASP.NET C#

Jan25
2012
14 Comments Written by Vikram

After reading alot on the net in this article will let you know with the help of jqueries that how can we upload the image and crop it according to our choice like we do in orkut or in facebook. i just tried to do something similar. Well,  first of all create folders name “images” which will keep the image for cropping and under images create “crop” name folder which will keep the proportionate cropped image files and last one create “Profile_pics” which will crop the proportionate cropped image once again and this one is optional you can remove that methods. In this article i have restricted the image size which is “200kb” only so you can  increase it. Hope you will like this article.

*create a page “Default2.aspx”

Now, Copy paste the source code below.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default2.aspx.cs” Inherits=”Default2″ %>

 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head id=”Head1″ runat=”server”>
<title>crop images asp.net</title>
<link href=”jquery.Jcrop.css” rel=”stylesheet” type=”text/css” /><script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js”></script>
<script src=”js/jquery.Jcrop.min.js” type=”text/javascript”></script>
<script type=”text/javascript”>

jQuery(function($){

// To hold the API and image size.

var jcrop_api, boundx, boundy;
$(‘#img_crop’).Jcrop({  // img_crop is the ID of image control
onChange: updatePreview, // will display the selected img on change.
onSelect: updatePreview, // will display the selected img Img_preview
onSelect: storeCoords, // will tell the coordinates
aspectRatio: 1
},function(){
var bounds = this.getBounds();
boundx = bounds[0];
boundy = bounds[1];
jcrop_api = this;
});

function updatePreview(c)
{
if (parseInt(c.w) > 0)
{  var rx = 100 / c.w;
var ry = 100 / c.h;
$(‘#Img_preview’).css({  //Img_preview is the ID of image control
width: Math.round(rx * boundx) + ‘px’,
height: Math.round(ry * boundy) + ‘px’,
marginLeft: ‘-’ + Math.round(rx * c.x) + ‘px’,
marginTop: ‘-’ + Math.round(ry * c.y) + ‘px’     });
}   }; });

READ MORE »

Posted in Asp.net, Javascript - Tagged asp.net, crop image, jcrop, jquery, jquery and jcrop, Upload, upload images

Returning complete words with a Left and Charindex in sql server

Jan23
2012
2 Comments Written by Vikram

Here i m explaining that how can we display the full string without any half word e.g. 1st line output with header name string will let you know about the substring in which the last word ‘industry’ is not proper displaying as such i have used a substring function with 100 characters. so thats why its not displaying the full word. To overcome this problem i have tried  something after search on the web and posting it on my website  which might helpful for u .

* this query can help us where we have to display news with read more …

– below variable @Str decalaration

Declare @Str varchar(200)

– assigning the String in @Str

set @Str =’Lorem Ipsum is simply dummy text of the printing & typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type.’

– substring 100 characters from @Str
select substring(@Str,0,100) as string

 

– with left and charindex keyword displaying the full words.
select Left(Left(@Str, 100), LEN(Left(@Str, 100)) – CHARINDEX(‘ ‘, REVERSE(Left(@Str, 100)))) AS msg

OUPTUT

*click on the below image and see the red mark at the string header named output

with regards
vik

Posted in Sql Server - Tagged Charindex, Left, sql, sql server

Getting the isoweek number sql server 2005

Jan21
2012
Leave a Comment Written by Vikram

Hello there, Actually i was facing problem last year to get the exact week no. of the year.  i found the following code which will let us know the exact week no. of the year. so, i thought to put an article on my site. It will help to other also.  just copy and paste the following script into your database to get the isoweek / week number.

 

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE FUNCTION [dbo].[ISOweek]  (@DATE DATETIME)

RETURNS INT

AS

BEGIN

DECLARE @ISOweek INT

SET @ISOweek= DATEPART(wk,@DATE)+1

-DATEPART(wk,CAST(DATEPART(yy,@DATE) AS CHAR(4))+’0104′)

–Special cases: Jan 1-3 may belong to the previous year

IF (@ISOweek=0)

SET @ISOweek=dbo.ISOweek(CAST(DATEPART(yy,@DATE)-1

AS CHAR(4))+’12′+ CAST(24+DATEPART(DAY,@DATE) AS CHAR(2)))+1

–Special case: Dec 29-31 may belong to the next year

IF ((DATEPART(mm,@DATE)=12) AND

((DATEPART(dd,@DATE)-DATEPART(dw,@DATE))>= 28))

SET @ISOweek=1

RETURN(@ISOweek)

END

GO

 

——————————————————————————————————–

How to execute see the following example..

select getdate() as currentdate
select DBO.ISOWEEK(getdate()) as weekno

 

 

with Regards
vik

Posted in Sql Server - Tagged isoweek, isoweek number, server, sql

How to check all CheckBox in GridView in asp.net C#

Jan19
2012
Leave a Comment Written by Vikram

Hello there, this time I will do something like we do in our email inbox items where we can delete our emails one by one or all at once after selecting the Checkbox. I have tried with database for simple example and you can do it according to your requirements. Hope you will like this post.

DATABASE SCRIPT

  • Create a database and name to db_gridview_chkbox and copy paste the following script into your sql sever.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tbl_messages](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[to_subject] [varchar](500) NULL,
[from] [varchar](12) NULL,
[date] [datetime] NULL CONSTRAINT [DF_tbl_messages_date]  DEFAULT (getdate())
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

SOURCE CODE

  • Now add a new page and name it Default.aspx and copy paste the following source code in it.

READ MORE »

Posted in Asp.net - Tagged C#, CheckBoxe asp.net, Gridview, GridView C# asp.net

How can we limit the characters in multiline textbox asp.net using JavaScript

Oct20
2011
3 Comments Written by Vikram

Hello there, sometimes we need to restrict the character length in Multiline Textbox and we know we can achieve by our logic in code-behind. Why don’t we try JavaScript? So I found something and modify it according to my need.  Following the code which will restrict the limit of characters in TextBox.

 

Create web form [Default2.aspx] and copy paste the source code in it

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default2.aspx.cs” Inherits=”Default2″ %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

 

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Untitled Page</title>
<script  language=”JavaScript” type=”text/javascript”>
//****  for master page the control name will be changed so you can access those name under source code.
//**** it could  be –> ctl00$ContentPlaceHolder1$txt_commnets so u have to change it where u will use the textbox.
//****  and form name could be –> aspnetForm instead of Form1
var max=50;             // 50  = max characters // we can set according to our need.

READ MORE »

Posted in Javascript - Tagged JavaScript, limit characters, textbox

How can create Google Visualization: Geomap in asp.net

Oct19
2011
Leave a Comment Written by Vikram

Well after searching and reading some articles on GEO-Map  I found an article in which they have used the Json  with static WEBMETHOD members  but my  problem was to display the records in GRIDVIEW which is not possible to bind the control inside the static WEBMETHOD then I created a following code and method through which I achieved my result so  I thought why don’t make it an article on it and post it so it will be helpful for others too so, here the following code. Hope you will enjoy it.

*And I have created a database almost 252 countries and more than 4200+ states so you can edit if you found any mistake in it.

Click here download the Script.

Create a webform name default.aspx and paste the source code in it.

SOURCE CODE

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head runat=”server”>

<title>Untitled Page</title>
<script src=”scripts/jquery-1.3.2.min.js” type=”text/javascript”></script>
<script type=’text/javascript’ src=’http://www.google.com/jsapi’></script>
<script src=’http://maps.google.com/maps?file=api&v=2&key=ABCDEFG’ type=’text/javascript’></script>

</head>
<body>

READ MORE »

Posted in Asp.net - Tagged asp.net, Geomap, Google Map, Visualization: Geomap

How to do Shopping Cart in Asp.net C#

Oct07
2011
5 Comments Written by Vikram

Hello there, I am just trying to do Shopping Cart simple way. Hope it will help you. To create a shopping cart we almost used the Product Details like Quantity, Price, Code etc. and we can add it more columns according to requirement. Well in this article I m using only two pages name Products.aspx and shopping_cart.aspx from Products page I will send the id of product code to shopping cart page and fill the Gridview with the product detail after getting the id from Query string. Well copy the following Database Script.
*you can use product title and description as well in database.

DATABASE SCRIPT

DATABASE SCRIPT
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N’[dbo].[tbl_Product]‘) AND type in (N’U'))
BEGIN
CREATE TABLE [dbo].[tbl_Product](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[Image] [nvarchar](200) NULL,
[Title] [nvarchar](50) NULL,
[description] [nvarchar](max) NULL,
[our_price] [bigint] NULL,
[size] [nvarchar](20) NULL,
[Product_quantity] [bigint] NULL CONSTRAINT [DF_tbl_Product_Product_quantity]  DEFAULT ((0)),
[Product_code] [nvarchar](20) NULL,
[date] [datetime] NULL CONSTRAINT [DF_tbl_Product_date]  DEFAULT (getdate()),
CONSTRAINT [PK_tbl_Product] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END

 

In your Website Add two pages and name it.
(i) Products.aspx
(ii) Shopping_Cart.aspx
Add DATALIST control on Products.aspx page,
(to learn how to bind DATALIST refer this link:-  http://howtouseasp.net/datalist-paging-with-editing-deleting-and-updating-with-ado-net-way-c/
Add GRIDVIEW  control on Shopping_Cart.aspx,
(to learn how to bind GRIDVIEW refer this link:-  http://howtouseasp.net/how-to-use-gridview-with-insert-edit-update-delete-the-ado-net-way-c/

READ MORE »

Posted in Asp.net - Tagged . asp.net. C#, asp.net, C#, Shopping Cart

Alpha Numeric Digit Numbers for password asp.net

Aug29
2011
Leave a Comment Written by Vikram

Well here I m going to explain how can we generate random DIGITS No. and also Random ALPHA NUMERIC DIGITS No. for password. Hope it will help you.

for random numbers click:-  here

Create a method name Pin_password().

public string Pin_password(string rec)
{
string pin_pwd = string.Empty;
int j = 0;      //for Upper Case because it will generate the Character same as like ch[i] doing.

Random rnd = new Random();    // random class for random generate the numbers using .Next()

for (int i = 0; i <= 2; i++) // For loop
{
j = j + 1;      //increment the J variable for Random Characters.

// Create nums Array.
int[] nums = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

// create an characters Array for it.
char[] ch = new char[] { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’ };

nums[i] = nums[rnd.Next(0, 9)];
ch[i] = ch[rnd.Next(0, 20)];
ch[j] = ch[rnd.Next(0, 25)];

pin_pwd += nums[i].ToString() + ch[i].ToString() + ch[j].ToString().ToUpper();
// just add/append the nums and ch in pin_pwd.
//pin_pwd will store the string of random generated password.

}

if (con.State == ConnectionState.Closed)
{
con.Open();
}

// following will check the random generated no. is exists in database or not if YES then //generate new one for it.

adp = new SqlDataAdapter(“select LOWER(password) AS password from tbl_name  where password=@password “, con);
adp.SelectCommand.Parameters.AddWithValue(“@password”, pin_pwd.ToLower());
dt = new DataTable();
adp.Fill(dt);
adp.Dispose();
if (dt.Rows.Count == 0)
{
return pin_pwd;
dt.Dispose();

// if not found then return it.
}
else
{

// if record exits then generate new one and return it.
for (int i = 0; i <= 2; i++)
{
j = j + 1;
int[] nums = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
char[] ch = new char[] { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’ };
nums[i] = nums[rnd.Next(0, 9)];
ch[i] = ch[rnd.Next(0, 20)];
ch[j] = ch[rnd.Next(0, 25)];

pin_pwd += nums[i].ToString() + ch[i].ToString() + ch[j].ToString().ToUpper();
}
return pin_pwd;
dt.Dispose();
}
con.Close();
}

with regards
vik

OUTPUT:-

0tI1hE3gF

Posted in Asp.net - Tagged ALPHA NUMERIC DIGITS Numbers, DIGITS No., generate random DIGITS No., password, Random ALPHA NUMERIC DIGITS No.

Rtrim, Ltrim, Substring, Charindex,Upper, Lower, Reverse In Sql Server 2005

May20
2011
Leave a Comment Written by Vikram

I m just trying to some write down the some sql functions which is very useful for us as we know we can do these things in asp.net also but this is good if we have some knowledge about something better while developing something. I have just used some common functions which we use in our daily life while doing programming. Hope this will help you.
*Copying the following must replace the –> ‘ from keyboard.

[--] this sign is used for commenting the queries.
–Removing the spaces

DECLARE @str VARCHAR(50)
SET @str =’  Vikram Dhawan  ‘
select @str as [1. myname]
select LTRIM(@str)  as [2. LTRIM]
select RTRIM(@str)  as [3. RTRIM]
select LTRIM(RTRIM((@str)))  as [4. LTRIM/RTRIM]
–you can use here your table column name
–select LTRIM(RTRIM((yourcolumname))) from tablename
–SYNTAX SUBSTRING(expression,starting no.,length)

READ MORE »

Posted in Sql Server - Tagged Charindex, Lower, Ltrim, Reverse, Rtrim, Sql Server 2005, Substring, Upper
« Older Entries

Tags

. asp.net. C# ado.net asp.net C# case sensitive Charindex CheckBox control Convert Numbers database Databound Datalist Datalist paging Delete Deleting DetailsView display image dynamically E-mail Edit Editing Email folder dynamically FormView Gridview Image control images Insert linkbutton LINQ LINQ with Database LINQ with Database in Gridview ListBox multiple values Paging paypal Repeater Control sql sql server Thumbnail Update updating Ado.net upload images VB vb.net Words

Recent Posts

  • how to use isnull(), if, else if, while loop, return, select case in sql server
  • How to Upload and crop images with jquery in ASP.NET C#
  • Returning complete words with a Left and Charindex in sql server
  • Getting the isoweek number sql server 2005
  • How to check all CheckBox in GridView in asp.net C#

Categories

  • Asp.net
  • Javascript
  • Sql Server

EvoLve theme by Theme4Press  •  Powered by WordPress How to use Asp