string Data = " <message-submit-request><username>abc</username><password>abc</password><sender-id>DEMO</sender-id><MType>txt</MType><message-text><text>"+txtMSG.Text+" </text><to>"+num+"</to></message-text></message-submit-request>";
string newUrl = "http://203.129.101.201/sms/user/XML/send.php";
ApiPost(newUrl, Data);
public string ApiPost(string url, String strPost)
{
try
{
try
{
ASCIIEncoding encoding = new ASCIIEncoding();
string furl = url;
string fmessage = "data=" + strPost;
byte[] data = encoding.GetBytes(fmessage);
HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(url);
httpreq.Method = "POST";
httpreq.ContentType = "application/x-www-form-urlencoded";
httpreq.ContentLength = data.Length;
Stream newStream = httpreq.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
HttpWebResponse httpres = (HttpWebResponse)httpreq.GetResponse();
StreamReader sr = new StreamReader(httpres.GetResponseStream());
string results = sr.ReadToEnd();
return results;
}
catch
{
return "0";
}
}
catch
{
return "0";
}
}
Monday, December 20, 2010
Sunday, November 21, 2010
Detect browser name and all its setting in ASP.NET
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string browserset = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n";
string browserset = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n";
Detect browser name in ASP.NET
System.Web.
HttpBrowserCapabilities browser = Request.Browser;string s = "Browser Capabilities\n"+ "Type = " + browser.Type + "\n"+ "Name = " + browser.Browser + "\n"+ "Version = " + browser.Version + "\n"+ "Major Version = " + browser.MajorVersion + "\n"+ "Minor Version = " + browser.MinorVersion + "\n"+ "Platform = " + browser.Platform + "\n"+ "Is Beta = " + browser.Beta + "\n"+ "Is Crawler = " + browser.Crawler + "\n"+ "Is AOL = " + browser.AOL + "\n"+ "Is Win16 = " + browser.Win16 + "\n"+ "Is Win32 = " + browser.Win32 + "\n"+ "Supports Frames = " + browser.Frames + "\n"+ "Supports Tables = " + browser.Tables + "\n"+ "Supports Cookies = " + browser.Cookies + "\n"+ "Supports VBScript = " + browser.VBScript + "\n"+
browser.EcmaScriptVersion.ToString() + "Supports JavaScript = " +"\n"+ "Supports Java Applets = " + browser.JavaApplets + "\n"+
+ "Supports ActiveX Controls = " + browser.ActiveXControls"\n";
HttpBrowserCapabilities browser = Request.Browser;string s = "Browser Capabilities\n"+ "Type = " + browser.Type + "\n"+ "Name = " + browser.Browser + "\n"+ "Version = " + browser.Version + "\n"+ "Major Version = " + browser.MajorVersion + "\n"+ "Minor Version = " + browser.MinorVersion + "\n"+ "Platform = " + browser.Platform + "\n"+ "Is Beta = " + browser.Beta + "\n"+ "Is Crawler = " + browser.Crawler + "\n"+ "Is AOL = " + browser.AOL + "\n"+ "Is Win16 = " + browser.Win16 + "\n"+ "Is Win32 = " + browser.Win32 + "\n"+ "Supports Frames = " + browser.Frames + "\n"+ "Supports Tables = " + browser.Tables + "\n"+ "Supports Cookies = " + browser.Cookies + "\n"+ "Supports VBScript = " + browser.VBScript + "\n"+
browser.EcmaScriptVersion.ToString() + "Supports JavaScript = " +"\n"+ "Supports Java Applets = " + browser.JavaApplets + "\n"+
+ "Supports ActiveX Controls = " + browser.ActiveXControls"\n";
Function to check browser name in javascript
function check_browser()
{
try
{
var browserName=navigator.appName;
var browserVer=parseInt(navigator.appVersion);
if ((navigator.userAgent.indexOf('MSIE') != -1) && browserVer>=4)
{
browser_name='IE';
}
else if((navigator.userAgent.indexOf('Chrome') != -1) && browserVer>=4)
{
browser_name='Chrome';
}
else
{
browser_name='FireFox';
}
}
}
{
try
{
var browserName=navigator.appName;
var browserVer=parseInt(navigator.appVersion);
if ((navigator.userAgent.indexOf('MSIE') != -1) && browserVer>=4)
{
browser_name='IE';
}
else if((navigator.userAgent.indexOf('Chrome') != -1) && browserVer>=4)
{
browser_name='Chrome';
}
else
{
browser_name='FireFox';
}
}
}
Tuesday, November 16, 2010
Displaying Warning Message
link.Attributes.Add("onclick","return confirm('Are you sure you want to delete this data?');");
Monday, November 15, 2010
Set Date Format In Label Witth Data Binding
where date is a database field
We can also set it as
<asp:Label ID="Label1" runat="server" Text='<%= String.Format("{specifier}", DateTime.Now)%'></asp:Label>
Text='<%# Eval("date","{0:M}"<asp:Label ID="Label1" runat="server" Text='<%# Eval("date","{0:M}")%>'></asp:Label>
Tuesday, November 9, 2010
Set Character length of linkbutton
<asp:LinkButton ID="linknews" ForeColor="Black" Font-Underline="false" runat="server" Text='<%# Eval("news").ToString().Substring(0,80)%>'></asp:LinkButton>
Select Substring Query in sql server
SELECT
(CASE WHEN LEN( address) > 25
THEN SUBSTRING(address,0,25)
ELSE address END
)as address
FROM emp_details
(CASE WHEN LEN( address) > 25
THEN SUBSTRING(address,0,25)
ELSE address END
)as address
FROM emp_details
Tuesday, November 2, 2010
XML NODE TRAVERSE IN ASP.NET
public void TravelNode(XmlNode n)
{
TravelNode(n, 0);
}
public void TravelNode(XmlNode n, int i)
{
foreach (XmlAttribute attr in n.Attributes)
{
string v = attr.Name;
string na = attr.Value;
if (v == "Code")
{
status = "Not Delievered";
break;
}
else
{
status = "Delievered";
}
}
foreach (XmlNode nod in n.ChildNodes)
{
TravelNode(nod, i + 1);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
String dr="<?xml%20version=\"1.0\"%20encoding=\"ISO-8859-1\"?><!DOCTYPE%20REQUESTCREDIT%20SYSTEM%20\"http://107.10.10.01/dtd/requestcredit.dtd\"%20>";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(dr);
TravelNode(xmlDoc.DocumentElement);
}
READ XML DOCUMENT IN ASP.NET
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Xml;
Stream objStream = null;
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(data);
try
{
objStream = wrGETURL.GetResponse().GetResponseStream();
}
catch (Exception ex)
{
ex.ToString();
}
StreamReader sr = new StreamReader(objStream);
string dr = sr.ReadToEnd();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(dr);
foreach (XmlNode nod in xmlDoc.DocumentElement)
{
foreach(XmlAttribute attr in nod.Attributes)
{
string na = attr.Name;
string v = attr.Value;
if (na.Equals("Limit"))
{
LblLimitName.Text = na;
LblLimitValue.Text = v;
}
else if(na.Equals("Used"))
{
LblUsedName.Text = na;
LblUsedValue.Text = v;
}
}
}
sr.Close();
objStream.Close();
Change Image Align,Image URL,Width,Height Programatically
protected void Page_Load(object sender, EventArgs e)
{
Image img = new Image();
img.ImageUrl = ds.Tables[0].Rows[0]["image"].ToString();
img.ImageAlign = ImageAlign.Left;
img.Width = new Unit("100px");
img.Height = new Unit("50px");
}
{
Image img = new Image();
img.ImageUrl = ds.Tables[0].Rows[0]["image"].ToString();
img.ImageAlign = ImageAlign.Left;
img.Width = new Unit("100px");
img.Height = new Unit("50px");
}
Monday, November 1, 2010
INSERT THE AUTO INCREMENTED COLUMN IN GRIDVIEW
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="AUTOINCREMENT FIELD">
<ItemTemplate>
<asp:Label ID="Label1" runat="server"><%# Container.DataItemIndex + 1 %></asp:Label></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
USE the DataItemIndex Property
<Columns>
<asp:TemplateField HeaderText="AUTOINCREMENT FIELD">
<ItemTemplate>
<asp:Label ID="Label1" runat="server"><%# Container.DataItemIndex + 1 %></asp:Label></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
USE the DataItemIndex Property
SET DATE TIME FORMAT IN GRIDVIEW
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"><Columns><asp:BoundField DataField="date" DataFormatString="{0:d}" HeaderText="Date" /></Columns>
</asp:GridView>
</asp:GridView>
Sunday, October 31, 2010
Create View
create view VIEW_first
AS
SELECT E.name,C.fname FROM emp E,copy1 C
select * from VIEW_first
AS
SELECT E.name,C.fname FROM emp E,copy1 C
select * from VIEW_first
VIEWS IN SQL SERVER
A view is a virtual table that consists of columns from one or more tables. Though it is similar to a table, it is stored in the database. It is a query stored as an object. Hence, a view is an object that derives its data from one or more tables. These tables are referred to as base or underlying tables.
Once you have defined a view, you can reference it like any other table in a database.
A view serves as a security mechanism. This ensures that users are able to retrieve and modify only the data seen by them. Users cannot see or access the remaining data in the underlying tables. A view also serves as a mechanism to simplify query execution. Complex queries can be stored in the form as a view, and data from the view can be extracted using simple queries.
Example
Consider the Publishers table below. If you want users to see only two columns in the table, you can create a view called vwPublishers that will refer to the Publishers table and the two columns required. You can grant Permissions to users to use the view and revoke Permissions from the base Publishers table. This way, users will be able to view only the two columns referred to by the view. They will not be able to query on the Publishers table.
Publishers
Publd | PubName | City | State | Country |
036 | New Books | Boson | MA | USA |
077 | Binnet | Wasngton | DC | USA |
138 | Algodata | Berkey | CA | USA |
162 | Five Lakes Publishing | Chicgo | IL | USA |
VW Publishers
Publd | PubName |
073 | New Moon Books |
087 | Binnet & Hardly |
138 | Algodata |
162 | Five Lakes |
Views ensure the security of data by restricting access to the following data:
- Specific rows of the tables.
- Specific columns of the tables.
- Specific rows and columns of the tables.
- Rows fetched by using joins.
- Statistical summary of data in a given tables.
- Subsets of another view or a subset of views and tables.
Some common examples of views are:
- A subset of rows or columns of a base table.
- A union of two or more tables.
- A join of two or more tables.
- A statistical summary of base tables.
- A subset of another view, or some combination of views and base table.
TRIGGER ON DATA UPDATION
create trigger afterupdate
on emp
AFTER UPDATE
as
begin
declare @name varchar(50)
declare @fname varchar(50)
declare @ser numeric(18,0)
select @name=name from inserted
select @fname=fname from inserted
select @ser=ser_num from inserted
update copy set name=@name ,fname=@fname where ser_num=@ser
PRINT 'AFTER TRIGGER EXECUTED SUCESSFULLY'
end
GO
insert into emp(name,fname)values('abc','xyz');
update emp set name='ajay', fname='sh.sp sharma' where ser_num='7'
TRIGGER ON AFTER INSERTION OF DATA
create trigger afterinsert_trigger1
on emp
AFTER INSERT
as
begin
declare @name varchar(50)
declare @fname varchar(50)
select @name=name from inserted
select @fname=fname from inserted
select @ser=ser_num from inserted
insert into copy(name,fname,ser_num)values(@name,@fname,@ser)
PRINT 'AFTER TRIGGER EXECUTED SUCESSFULLY'
end
GO
insert into emp(name,fname)values('xzz','xxaa');
(1 row(s) affected)
AFTER TRIGGER EXECUTED SUCESSFULLY
(1 row(s) affected)
select * from copy
Types of triggers in sql server with example
Types of Triggers
Triggers are of 3 types in SQL Server 2005:
1. DMLTriggers
. AFTER Triggers
.INSTEAD OF Triggers
2. DDL Triggers
3. CLR Triggers
Note:DDL and CLR Triggers cannot work in SQL Server 2000
DML Trigger:-These Trigger is fired only when INSERT, UPDATE, and DELETE Statement occurs in table.
Explanation on DML Trigger:
Let us create a Table and insert some records in that Table.
1)After Triggers:
After Triggers can be created in 3 ways.1) After INSERT
2) After UPDATE
3) After DELETE
1) creating After INSERT Trigger:-
Syntax:create trigger triggername on tablename AFTER INSERT
As
[SQL Statement/PRINT Command]
GO
Eg:
create trigger afterinsert_trigger on emp AFTER INSERT
as
PRINT 'AFTER TRIGGER EXECUTED SUCESSFULLY'
GO
When you execute the afterinsert_trigger it gives message as 'The Command(s) created successfully'
You can see the is trigger is created.
Now insert one record in a emp table. You can see the trigger will be fired automatically when the row is inserted in a table successfully.
Creating AFTER UPDATE TRIGGER:-
create trigger afterupdate_trigger
on emp
AFTER UPDATE
as
PRINT 'AFTER UPDATE TRIGGER EXECUTED SUCESSFULLY'
GO
Creating AFTER DELETE TRIGGER:
Create trigger afterdelete_trigger
On emp
AFTER DELETE
as
PRINT 'AFTER DELETE TRIGGER EXECUTED SUCESSFULLY'
GO
Instead Of Update Trigger
Creating INSTEAD OF UPDATE TRIGGER:-
create trigger insteadofupdate_trigger
on emp
INSTEAD OF UPDATE
as
PRINT 'INSTEAD OF UPDATE TRIGGER EXECUTED SUCESSFULLY'
GO
create trigger insteadofupdate_trigger
on emp
INSTEAD OF UPDATE
as
PRINT 'INSTEAD OF UPDATE TRIGGER EXECUTED SUCESSFULLY'
GO
Instead of Delete Trigger
Creating INSTEAD OF DELETE TRIGGER:-
create trigger insteadofdelete_trigger
on emp
INSTEAD OF DELETE
as
PRINT 'INSTEAD OF DELETE TRIGGER EXECUTED SUCESSFULLY'
GO
create trigger insteadofdelete_trigger
on emp
INSTEAD OF DELETE
as
PRINT 'INSTEAD OF DELETE TRIGGER EXECUTED SUCESSFULLY'
GO
Subscribe to:
Posts (Atom)