Friday, May 23, 2008

keyword searching result from database in C#

public static DataSet RelatedKeyword(string keyword)

{string[] arr =keyword.Replace("& ","").Split(' ');

DataSet ds = new DataSet();

DataSet dsTemp = new DataSet();

bool flag = false;

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["remote"].ConnectionString);

// DBAccess db = new DBAccess();

SqlDataAdapter sda;

foreach (string s in arr)

{ if (s.Length >= 2)

{ sda = new SqlDataAdapter("select distinct top 60 keywordid, keywordname from keyword  where keywordname like '%'+@ksearch+'%'", con);

sda.SelectCommand.Parameters.Add("@ksearch", SqlDbType.VarChar).Value = s;

sda.Fill(dsTemp);

sda.SelectCommand.Parameters.Clear();

ds.Merge(dsTemp);

if (flag == false)

{DataColumn[] pk = new DataColumn[1];

pk[0] = ds.Tables[0].Columns["keywordid"];

ds.Tables[0].PrimaryKey = pk;

flag = true;

}}}

return ds;}

send data from html page to server pages

 


head>

<title>Untitled Page</title>

<script language=javascript>

function submitvalue()

{

var red=document.getElementById('rd');

var val="PH";

if(rd[0].checked==true)

{val="KH";

}

window.location.href="keywordsearch.aspx?kq="+document.getElementById('txtsearch').value+"&stype="+val;

}

</script>

</head>

<body>

<input type=text name="txtsearch" runat=server />

<input type=radio name="rd" value="KH" runat=server checked=checked/>

<input type="radio" name="rd" value="PH" runat=server/>

<input type="button" name="btnsearch" value="search" onclick="submitvalue();"/>

</body>

Friday, May 16, 2008

Open .aspx page with parameter in popup window



<a href=”javascript:return false;” onclick=”javascript:window.open(’sendquery.aspx?rg=” + sd.REGID + “&comp=” + sd.COMPANYNAME + “&city=” + sd.CITYNAME + “‘,’smallwindowsms’,'toolbars=0,crollbars=0,width=600,

height=500,menubar=0,resizable=0′);return false;”>send query</a>

Thursday, May 15, 2008

protect copy of data on page in javascript

<



SCRIPT language=javascript type=text/javascript> 

function disableCtrlKeyCombination(e)

{//list all CTRL + key combinations you want to disable 

var forbiddenKeys = new Array('a', 'n', 'c', 'x', 'v', 'j');

var key;var isCtrl;

if(window.event)

{key = window.event.keyCode; //IE

if(window.event.ctrlKey)

isCtrl = true;

else

isCtrl = false;

}

else

{key = e.which; //firefox

if(e.ctrlKey)

isCtrl = true;

else

isCtrl = false;

}

//if ctrl is pressed check if other key is in forbidenKeys array

if(isCtrl)

{for(i=0; i<forbiddenKeys.length; i++)

{// alert(forbiddenKeys[i]);

//case-insensitive comparation

if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())

{// alert('Key combination CTRL + ' +String.fromCharCode(key) +' has been disabled.');

return false;

}}}

return true;



function click(e) {

if (document.all) {

if (event.button == 2) {

//alert(message);

return false;

}}

if (document.layers) {

if (e.which == 3) {

// alert(message);

return false;

}}}

if (document.layers) {

document.captureEvents(Event.MOUSEDOWN);

}

document.onmousedown=click;

</script>

in body tag write

<body oncontextmenu="return false" onkeypress

="return disableCtrlKeyCombination(event);" onkeydown="return disableCtrlKeyCombination(event);" >

Edit,Update and delete in datalist

<!-- start html code -->

<asp:DataList ID=rp runat=server DataKeyField="localityid" RepeatColumns=2 RepeatLayout=Table Width=400px OnCancelCommand=Cancel_Command OnEditCommand=edit OnUpdateCommand=update OnDeleteCommand=delete>

<ItemTemplate>

<asp:Label ID=lbl runat=server Text='<%#Eval("localityid") %>'></asp:Label>

<asp:Label ID=lbl1 runat=server Text='<%#Eval("localityname") %>'></asp:Label>

<asp:Button ID=edit Text=Edit CommandName=edit runat=server />

<asp:Button ID=delete Text=Delete CommandName=delete runat=server />

</ItemTemplate>

<EditItemTemplate>

<asp:TextBox ID=locid runat=server Text='<%#Eval("localityid") %>'></asp:TextBox>

<asp:TextBox ID=locname runat=server Text='<%#Eval("localityname") %>'></asp:TextBox>

<asp:Button ID=update Text=Update CommandName=update runat=server />

<asp:Button ID="Cancle" Text="Cancle" CommandName="cancel" runat=server />

</EditItemTemplate>

 

</asp:DataList> 

<!--End html code --> 

<!--In codebehind -->

using System;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls; 

public partial class editingindatalist : System.Web.UI.Page

{

SqlConnection con = new SqlConnection("Server=.;Database=raj;uid=sa;pwd=sa");

protected void Page_Load(object sender, EventArgs e)

{ if (!Page.IsPostBack)

{this.binddata();// for data bind to datalist Control }

}

protected void Cancel_Command(object source, DataListCommandEventArgs e)

{ rp.EditItemIndex =-1;

this.binddata();

}

protected void delete(object source, DataListCommandEventArgs e)

{

int id = Convert.ToInt32(rp.DataKeys[e.Item.ItemIndex]);

SqlCommand cmd = new SqlCommand();

cmd.Connection = con;

cmd.Parameters.Add("@locid", SqlDbType.Int).Value = id;

cmd.CommandText = "delete from locality where localityid=@locid";

cmd.Connection.Open();

cmd.ExecuteNonQuery();

cmd.Connection.Close();

binddata(); 

}

protected void edit(object source, DataListCommandEventArgs e)

{ rp.EditItemIndex = e.Item.ItemIndex;

binddata();

}

protected void update(object source, DataListCommandEventArgs e)

{ int id = Convert.ToInt32(rp.DataKeys[e.Item.ItemIndex]);

SqlCommand cmd = new SqlCommand();

cmd.Connection = con;

cmd.Parameters.Add("@locname", SqlDbType.VarChar).Value = ((TextBox)e.Item.FindControl("locname")).Text;

cmd.Parameters.Add("@locid", SqlDbType.Int).Value = id;

cmd.CommandText = "update locality set localityname=@locname WHERE localityid=@locid";

cmd.Connection.Open();

cmd.ExecuteNonQuery();

cmd.Connection.Close();

rp.EditItemIndex = -1;

this.binddata();

}

protected void binddata()

{ SqlCommand cmd = new SqlCommand();

cmd.Connection = con;

cmd.CommandText = "select * from locality WHERE localityid in(select localityid from localityassign where cityid=3)";

cmd.Connection.Open();

SqlDataReader rdr = cmd.ExecuteReader();

rp.DataSource = rdr;

rp.DataBind();

cmd.Connection.Close(); 

}}

Wednesday, May 14, 2008

using datediff function in sql

select datediff(year,'Nov 30 2001',getdate()) as diffyear 

select datediff(month,'Nov 30 2001',getdate())as diffmonth
 select datediff(day,'Nov 30 2001',getdate()) as diffdaydiffyear

 diffyear

-----------

 7 (1 row(s) affected)

diffmonth

-----------

78(1 row(s) affected)

diffday

----------

2357(1 row(s) affected)

using datename function for name of month,day

 


select DATENAME(w, GETDATE()) AS ' Day Name'

day name

---------
Wednesday

SELECT DATENAME(m, GETDATE()) AS ' month Name'

month name

---------

may

 

 

 

Using Dateadd function adding day,month,year in date


select


dateadd(datepart,number,date)

eg-



select


DATEADD(month, 3, getdate()) 



Datepart


|Abbreviations

year| yy,yyyy 

quarter| qq,

month| mm,

dayofyear| dy,

day| dd,

week| wk,ww 

weekday| dw,

hour| hh

minute| mi,

second| ss, s

Tuesday, May 13, 2008

fixed header in Datagrid,Gridview in asp.net

<head runat="server">
<title>Untitled Page</title>
</head>
<script type="text/javascript">   
function showheader()
{
var ab= document.getElementById("<%=gd.ClientID%>");
var pnid = document.getElementById("<%=pn.ClientID%>");
var abc = ab.cloneNode(true);
var i = abc.rows.length -1;
for(;i>0;i--)
abc.deleteRow(i)
ab.deleteRow(0)
pnid.appendChild(abc)
}
window.onload =showheader
</script>

<body>
<form id="form1" runat="server">
<div><asp:Panel ID=pn runat=server></asp:Panel>
<asp:Panel ID=pnn runat=server style="overflow-y:scroll;height: 250px;weight:300px" >
<asp:GridView ID="gd" runat="server">
</asp:GridView>
</asp:Panel>
</div>
</form>
</body>
code file//////////
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("Server=.;Database=dbdata;uid=sa;pwd=sa");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select top 100 * from locality";
cmd.Connection.Open();
SqlDataReader rdr = cmd.ExecuteReader();
gd.DataSource = rdr;
gd.DataBind();
cmd.Connection.Close();

}

Monday, May 12, 2008

Sending mail in asp.net

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From=new MailAddress("mymail@gmail.com");
mail.To.Add(new MailAddress("sendmail@yahoo.com"));//enter company name which send
mail.IsBodyHtml=true;
mail.Subject = "Sending Enquiry";
mail.Body = "Enquiry About Company ";
//Proper Authentication Details need to be passed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential("maymail@gmail.com", "password");
//Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587
//For different server like yahoo this details changes and you can
//get it from respective server.
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com",587);
//Enable SSL
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(mail);
Response.Flush();
Response.Write("message was sent successfully!!!");

 

export data in excel in single sheet

protected void exporttoexcel_Click(object sender, EventArgs e)

{Response.Clear();

Response.Buffer = true;

Response.ContentType = "application/vnd.ms-excel";

Response.ContentEncoding = System.Text.Encoding.UTF7;

Response.AddHeader("Content-Disposition", "attachment;filename=report.xls");

Response.Charset = "";

this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

rpt.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();

}

Edit ,Update , Delete in Repeater in asp.net

<script>

function isconfirm()

{

var ck=confirm('Are you sure to delete');

if(ck==true)

return true;

else

return false;

}

</script>

< asp:Repeater ID="Rp" OnItemCommand="Action" runat="server">

<ItemTemplate>

<div>

<asp:Label ID="sno" Text='<%#Eval("sno") %>' runat=server Visible=false></asp:Label>

<asp:Label ID="lblname" Text='<%#Eval("name1") %>' runat=server></asp:Label><br />

<asp:Label ID="lblamt" Text=' <%#Eval("amt") %>' runat=server></asp:Label>

<asp:TextBox ID="txtname" Text='<%#Eval("name1") %>' runat=server Visible=false></asp:TextBox><br />

<asp:TextBox ID="txtamt" Text='<%#Eval("amt") %>' runat=server Visible=false></asp:TextBox>

<asp:Button ID="btn" runat=server Text="Edit" CommandArgument="ek" CommandName="Action" />

<asp:Button ID="btnd" runat=server Text="Delete" CommandArgument="dk" CommandName="Action" OnClientClick="return isconfirm()" />

</div>

</ItemTemplate>

<SeparatorTemplate><hr/></SeparatorTemplate>

</asp:Repeater>

In codebehind code
public



partial class imageclick : System.Web.UI.Page

{SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

getdata();

}

}

void getdata()

{

SqlDataAdapter sda = new SqlDataAdapter("select * from emp", con);

DataSet ds = new DataSet();

sda.Fill(ds);

Rp.DataSource = ds;

Rp.DataBind();

}

protected void Action(object o, RepeaterCommandEventArgs e)

{

int i = Rp.Items.Count;

int n = e.Item.ItemIndex;

for (int chk=0; chk< i; chk++)

{

if (chk != n)

{

((Button)Rp.Items[chk].FindControl("btn")).Enabled = false;

((Button)Rp.Items[chk].FindControl("btnd")).Enabled = false;

}

}

if (Convert.ToString(e.CommandArgument) == "ek")

{

if (((Button)e.Item.FindControl("btn")).Text == "Edit")

{

((Label)e.Item.FindControl("lblname")).Visible = false;

((Label)e.Item.FindControl("lblamt")).Visible = false;

((TextBox)e.Item.FindControl("txtname")).Visible = true;

((TextBox)e.Item.FindControl("txtamt")).Visible = true;

((Button)e.Item.FindControl("btnd")).Text = "Cencel";

((Button)e.Item.FindControl("btn")).Text = "Update";

// ((Button)e.Item.FindControl("btn")).CommandName = "Update";

}

else

{

string nm = ((TextBox)e.Item.FindControl("txtname")).Text;

int amt = Convert.ToInt32(((TextBox)e.Item.FindControl("txtamt")).Text);

int sno = Convert.ToInt32(((Label)e.Item.FindControl("sno")).Text);

update(sno, nm, amt);

getdata();

((Label)e.Item.FindControl("lblname")).Visible = true;

((Label)e.Item.FindControl("lblamt")).Visible = true;

((TextBox)e.Item.FindControl("txtname")).Visible = false;

((TextBox)e.Item.FindControl("txtamt")).Visible = false;

((Button)e.Item.FindControl("btn")).Text = "Edit";

}

}

else

{

if (((Button)e.Item.FindControl("btnd")).Text == "Delete")

{

int sno = Convert.ToInt32(((Label)e.Item.FindControl("sno")).Text);

delete(sno);

getdata();

}

else

{

getdata();

}

}

}

void delete(int sno)

{

SqlCommand cmd = new SqlCommand("delete from emp where sno=@sno", con);

cmd.Connection.Open();

cmd.Parameters.Add("@sno", SqlDbType.Int).Value = sno;

cmd.ExecuteNonQuery();

cmd.Connection.Close();

}

void update( int sno,string nm,int amt)

{

SqlCommand cmd = new SqlCommand("update emp set name1=@nm,amt=@am where sno=@sno", con);

cmd.Connection.Open();

cmd.Parameters.Add("@sno", SqlDbType.Int).Value=sno;

cmd.Parameters.Add("@nm", SqlDbType.VarChar).Value = nm;

cmd.Parameters.Add("@am", SqlDbType.Int).Value = amt;

cmd.ExecuteNonQuery();

cmd.Connection.Close();

}

}

Creating Datalayer in Class file

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace DATAACCESS.SQL
{
public class DATALAYER:IDisposable
{
private IDbCommand cmd=new SqlCommand();
private string strConnectionString="";
private bool handleErrors=false;
private string strLastError="";
public DATALAYER()
{
ConnectionStringSettings objConnectionStringSettings = ConfigurationManager.ConnectionStrings["connect"];
strConnectionString = objConnectionStringSettings.ConnectionString;
SqlConnection cnn=new SqlConnection();
cnn.ConnectionString=strConnectionString;
cmd.Connection=cnn;
cmd.CommandType = CommandType.StoredProcedure;
}
public IDataReader ExecuteReader()
{ IDataReader reader=null;
try
{
this.Open();
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
if (handleErrors)
strLastError = ex.Message;
else
throw;
}
return reader;
}
public IDataReader ExecuteReader(string commandtext)
{
IDataReader reader=null;
try
{
cmd.CommandText=commandtext;
reader=this.ExecuteReader();
}
catch(Exception ex)
{
if(handleErrors)
strLastError=ex.Message;
else
throw;
}
return reader;
}
public object ExecuteScalar()
{
object obj = null;
try
{ this.Open();
obj = cmd.ExecuteScalar();
this.Close();
}
catch (Exception ex)
{ if (handleErrors)
strLastError = ex.Message;
else
throw;
}
return obj;
}
public object ExecuteScalar(string commandtext)
{
object obj=null;
try
{ cmd.CommandText=commandtext;
obj= this.ExecuteScalar();
}
catch(Exception ex)
{ if(handleErrors)
strLastError=ex.Message;
else
throw;
}
return obj;
}

public int ExecuteNonQuery()
{
int i=-1;
try
{
this.Open();
i=cmd.ExecuteNonQuery();
this.Close();
}
catch(Exception ex)
{
if(handleErrors)
strLastError=ex.Message;
else
throw;
}
return i;
}
public int ExecuteNonQuery(string commandtext)
{
int i=-1;
try
{
cmd.CommandText=commandtext;
i=this.ExecuteNonQuery();
}
catch(Exception ex)
{
if(handleErrors)
strLastError=ex.Message;
else
throw;
}
return i;
}
public DataSet ExecuteDataSet()
{
SqlDataAdapter da=null;
DataSet ds=null;
try
{
da=new SqlDataAdapter();
da.SelectCommand=(SqlCommand)cmd;
ds=new DataSet();
da.Fill(ds);
}
catch(Exception ex)
{
if(handleErrors)
strLastError=ex.Message;
else
throw ex;
}
return ds;
}
public DataSet ExecuteDataSet(string commandtext)
{
DataSet ds=null;
try
{
cmd.CommandText=commandtext;
ds=this.ExecuteDataSet();
}
catch(Exception ex)
{
if(handleErrors)
strLastError=ex.Message;
else
throw;
}

return ds;
}

public string CommandText
{
get
{
return cmd.CommandText;
}
set
{
cmd.CommandText=value;
cmd.Parameters.Clear();
}
}

public IDataParameterCollection Parameters
{
get
{
return cmd.Parameters;
}
}

public void AddParameter(string paramname,object paramvalue)
{
SqlParameter param=new SqlParameter(paramname,paramvalue);
cmd.Parameters.Add(param);
}

public void AddParameter(IDataParameter param)
{
cmd.Parameters.Add(param);
}

public string ConnectionString
{
get
{
return strConnectionString;
}
set
{
strConnectionString=value;
}
}

private void Open()
{
cmd.Connection.Open();
}

private void Close()
{
cmd.Connection.Close();
}

public bool HandleExceptions
{
get
{
return handleErrors;
}
set
{
handleErrors=value;
}
}

public string LastError
{
get
{
return strLastError;
}
}

public void Dispose()
{
cmd.Dispose();
}
}

}

Friday, May 9, 2008

Create Rss using Generic handler

<%@ WebHandler Language="C#" Class="FeedRss" %>

using System;
using System.Text;
using System.Xml;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Configuration;
public class FeedRss : IHttpHandler {
public void ProcessRequest (HttpContext context) {
//context.Response.ContentType = "text/plain";
context.Response.Clear();
context.Response.ContentType = "text/xml";
XmlTextWriter rssfeed = new XmlTextWriter(context.Response.OutputStream,Encoding.UTF8);
rssfeed.WriteStartDocument();
// The mandatory rss tag
rssfeed.WriteStartElement("rss");
rssfeed.WriteAttributeString("version", "2.0");
// The channel tag contains RSS feed details
rssfeed.WriteStartElement("channel");
rssfeed.WriteElementString("title", "ljkfhjlkfhd News");
rssfeed.WriteElementString("link", "http:/hch.cjdjn");
rssfeed.WriteElementString("description", "The latest news from all over the world.");
rssfeed.WriteElementString("copyright", "dfgfdgfg All rights reserved.-Created by Suresh");
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connect"].ToString());
SqlCommand cmd = new SqlCommand("select * from news", con);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{

rssfeed.WriteStartElement("item");
rssfeed.WriteElementString("title", sdr["Title"].ToString());
rssfeed.WriteElementString("description", sdr["Description"].ToString());
rssfeed.WriteElementString("link", "http://localhost:4329/searchengine/View.aspx?View=" + sdr["articleid"]);
rssfeed.WriteElementString("category", sdr["category"].ToString());
rssfeed.WriteElementString("pubDate", sdr["pubdate"].ToString());
rssfeed.WriteElementString("ttl", sdr["ttl"].ToString());
rssfeed.WriteEndElement();
}
sdr.Close();
con.Close();
rssfeed.WriteEndElement();
rssfeed.WriteEndElement();
rssfeed.WriteEndDocument();
rssfeed.Flush();
rssfeed.Close();
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}

Data Show in DataList

<asp:DataList ID="Rp” runat="server" RepeatColumns=2 RepeatDirection=Horizontal>
<ItemTemplate>CompanyName: <%#Eval("Companyname") %><br/>
Address : <%#Eval("Address") %><br />
City: <%#Eval("City") %><br />
PinCode: <%#Eval("Pincode") %>
</ 
ItemTemplate></
asp:DataList>
in codbehind
rep.datasource=ds;
rep.Databind();

Thursday, May 8, 2008

Data display in Repeater control

<asp:Repeater ID="Rp"  runat="server">

<ItemTemplate>CompanyName: <%#Eval("Companyname") %><br />

Address : <%#Eval("Address") %><br />

City: <%#Eval("City") %><br />

PinCode: <%#Eval("Pincode") %>

</ItemTemplate>

<SeparatorTemplate><hr /></SeparatorTemplate>

</asp:Repeater>

in codbehind

rep.datasource=ds;

rep.Databind();

Wednesday, May 7, 2008

Ad show in time interval using timer and adrotator

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>

<asp:AdRotator ID=ad runat=server AdvertisementFile="~/adsbanner.xml" />

<asp:Timer ID=tm Interval=3000 runat="server">

</asp:Timer>

</ContentTemplate> 

</asp:UpdatePanel>

click count on image using generic handler

hi

if u want to count on clicking image u just use generic hander in asp.net like that

<a href="Handler.ashx?bid=d1&Al=right&url=excelexp.aspx" ><img src="Images/120x240-wc.gif" /></a>

and in Handler.ashx page u write program for count . and store in database or in xml file.
<%@ WebHandler Language="C#" Class="Handler" %>




using


System;


using System.Web;

 public class Handler : IHttpHandler {

 public void ProcessRequest (HttpContext context)

 {context.Response.ContentType = "text/plain";

string align=context.Request.QueryString["Al"];

string url = context.Request.QueryString["Url"];

//here u write your counting code and store in database or in xml file

context.Response.Redirect(url, true);

context.Response.End();

}

public bool IsReusable {

get {return false;}

}}

 

Tuesday, May 6, 2008

using datepart function get different output

selectdatepart(year,getdate())
selectdatepart(month,getdate())

select datepart(day,getdate())

select datepart(hour,getdate())

select datepart(minute,getdate())

select datepart(second,getdate())

select datepart(millisecond,getdate())

select datepart(weekday,getdate())

select datepart(dayofyear,getdate())

select datepart(quarter,getdate())

using convert function filter time or date only from datetime column

SELECT

 



convert(char(11), getdate(),109)

May  6 2008
SELECT

 



convert(char(8), getdate(),108)

12:51:32

and so on u can change according input different char length and style value

converting Date into string in different style

hi

i submit for converting date into string in different style by help of sql server help?

select



CONVERT(varchar,CONVERT(datetime,getdate()),106) as date

output

06 May 2008

other style u want help like this

0 or 100 | Default |mon dd yyyy hh:miAM (or PM)
 101 | U.S.| mm/dd/yyyy
 102 | ANSI |yy.mm.dd
 103|British/French|dd/mm/yy
 104|German|dd.mm.yy
 105|Italian|dd-mm-yy
 106 (1)|-|dd mon yy
 107 (1)|-|Mon dd, yy
 108|-  |hh:mm:ss
 9 or 109 (1, 2) |Default + milliseconds|mon dd yyyy hh:mi:ss:mmmAM (or PM)
 110|USA|mm-dd-yy
 111|JAPAN|yy/mm/dd
 112|ISO|yymmdd
 13 or 113 (1, 2) | Europe default + milliseconds| dd mon yyyy hh:mm:ss:mmm(24h)
 114|-|hh:mi:ss:mmm(24h)
 20 or 120 (2) |ODBC canonical| yyyy-mm-dd hh:mi:ss(24h)
 21 or 121 (2) |ODBC canonical (with milliseconds)| yyyy-mm-dd hh:mi:ss.mmm(24h)
 126 (4)|ISO8601|yyyy-mm-ddThh:mm:ss.mmm (no spaces)
 127(6)|ISO8601 with time zone Z.|yyyy-mm-ddThh:mm:ss.mmmZ
 130 (1, 2)|Hijri (5)|dd mon yyyy hh:mi:ss:mmmAM
 131 (2)|Hijri (5)|dd/mm/yy hh:mi:ss:mmmAM
 

Saturday, May 3, 2008

create custom database for Membership,role,profile in sql server

if u want to use custom database on the sqlserver insteade of database in App_Data folder

u use following instruction
to create membership and role ,profile in ur database
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727>aspnet_regsql.exe -E -S sureshserver -d Useraccount -A mr

Start adding the following features:
Membership
RoleManager

..................

Finished.

for help

C:WINDOWSMicrosoft.NETFrameworkv2.0.50727>aspnet_regsql.exe /?

Administrative utility to install and uninstall ASP.NET features on a SQL
server.
Copyright (C) Microsoft Corporation. All rights reserved.

 

                             -- GENERAL OPTIONS --

-?                Display this help text.

-W                Wizard mode. (Default if no other parameters are specified.)
                          -- SQL CONNECTION OPTIONS --

-S <server>       SQL Server instance (SQL Server 7.0 and above) to work with.

-U <login id>     SQL Server user name to authenticate with; requires -P
                  option.

-P <password>     SQL Server password to authenticate with; requires -U option.

-E                Authenticate with current Windows credentials.

-C <connection string>
                  Connection string. Instead of specifying a user name,
                  password, and server name, specify a SQL Server connection
                  string. The string must not contain a database name unless
                  otherwise specified.

-sqlexportonly <filename>
                  Generate the SQL script file for adding or removing the
                  specified features and do not carry out the actual operation.
                  Can be used with the following options: -A, -R, -ssadd, and
                  -ssremove.
                       -- APPLICATION SERVICES OPTIONS --

-A all|m|r|p|c|w  Add support for a feature. Multiple values can be specified
                  together. For example:

                      -A mp
                      -A m -A p

                  all: All features
                  m: Membership
                  r: Role manager
                  p: Profiles
                  c: Personalization
                  w: SQL Web event provider

-R all|m|r|p|c|w  Remove support for a feature. Multiple values can be
                  specified together. For example:

                      -R mp
                      -R m -R p

                  all : All features plus all common tables and stored
                  procedures shared by the features
                  m: Membership
                  r: Role manager
                  p: Profiles
                  c: Personalization
                  w: SQL Web event provider

-d <database>     Database name for use with application services. If no
                  database name is specified, the default database "aspnetdb"
                  is used.

-Q                Quiet mode; do not display confirmation to remove a feature.

 

           -- SQL CACHE DEPENDENCY OPTIONS (FOR SQL 7.0 AND 2000) --

-d <database>     Database name for use with SQL cache dependency in SQL 7.0
                  and SQL 2000. The database can optionally be specified using
                  the connection string with the -C option instead. (Required)

-ed               Enable a database for SQL cache dependency.

-dd               Disable a database for SQL cache dependency.

-et               Enable a table for SQL cache dependency. Requires -t option.

-dt               Disable a table for SQL cache dependency. Requires -t option.

-t <table>        Name of the table to enable or disable for SQL cache
                  dependency. Requires -et or -dt option.

-lt               List all tables enabled for SQL cache dependency.
                          -- SESSION STATE OPTIONS --

-ssadd            Add support for SQLServer mode session state.

-ssremove         Remove support for SQLServer mode session state.

-sstype t|p|c     Type of session state support:

                  t: temporary. Session state data is stored in the "tempdb"
                  database. Stored procedures for managing session are
                  installed in the "ASPState" database. Data is not persisted
                  if you restart SQL. (Default)

                  p: persisted. Both session state data and the stored
                  procedures are stored in the "ASPState" database.

                  c: custom. Both session state data and the stored procedures
                  are stored in a custom database. The database name must be
                  specified.

-d <database>     The name of the custom database to use if -sstype is "c".

C:WINDOWSMicrosoft.NETFrameworkv2.0.50727>
AJAX, asp, Asp.net, asp.net and sql server security, Asp.net IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath