ASP.NET with C# and SQL SERVER , some vb.net . asp.net examples, asp.net codes, asp.net programs, c# code, sql server queries, important codes.
Saturday, 15 June 2013
view in sql server
==============================================================
View:-
==========================================================
CREATE VIEW InvoiceHeaders (customer_nbr, order_tot, ..)
AS
SELECT customer_nbr,
SUM(order_qty * unit_price),
..
FROM Invoices AS I, InvoiceDetails AS D
WHERE I.invoice_nbr = D.invoice_nbr
GROUP BY customer_nbr;
==============================================================
Large file uploads in ASP.NET,increase file upload size ,Increasing the Maximum Upload Size
Large file uploads in ASP.NET
Uploading files via the FileUpload control gets tricky with big files. The default maximum filesize is 4MB - this is done to prevent denial of service attacks in which an attacker submitted one or more huge files which overwhelmed server resources. If a user uploads a file larger than 4MB, they'll get an error message: "Maximum request length exceeded."
Increasing the Maximum Upload Size
The 4MB default is set in machine.config, but you can override it in you web.config. For instance, to expand the upload limit to 20MB, you'd do this:
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
Since the maximum request size limit is there to protect your site, it's best to expand the file-size limit for specific directories rather than your entire application. That's possible since the web.config allows for cascading overrides. You can add a web.config file to your folder which just contains the above, or you can use the <location> tag in your main web.config to achieve the same effect:
<location path="Upload">
<system.web>
<httpRuntime executionTimeout="110" maxRequestLength="20000" />
</system.web>
</location>
Uploading files via the FileUpload control gets tricky with big files. The default maximum filesize is 4MB - this is done to prevent denial of service attacks in which an attacker submitted one or more huge files which overwhelmed server resources. If a user uploads a file larger than 4MB, they'll get an error message: "Maximum request length exceeded."
Increasing the Maximum Upload Size
The 4MB default is set in machine.config, but you can override it in you web.config. For instance, to expand the upload limit to 20MB, you'd do this:
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
Since the maximum request size limit is there to protect your site, it's best to expand the file-size limit for specific directories rather than your entire application. That's possible since the web.config allows for cascading overrides. You can add a web.config file to your folder which just contains the above, or you can use the <location> tag in your main web.config to achieve the same effect:
<location path="Upload">
<system.web>
<httpRuntime executionTimeout="110" maxRequestLength="20000" />
</system.web>
</location>
sms is not sending
this code will allow to send sms
<location allowOverride="false">
<system.web>
<trust level="Full" originUrl="" />
</system.web>
</location>
<location allowOverride="false">
<system.web>
<trust level="Full" originUrl="" />
</system.web>
</location>
send sms in asp.net c#
-----------------------------------------------------------------
using System.Web.Services;
using System.Net;
public void sendsms()
{
try
{
string smsMessage = "Welcome In AEEI" + "\r";
smsMessage += txt_msg.Text.Trim();
string MobileNo = txt_mobileno.Text.Trim();
WebClient client = new WebClient();
if (MobileNo != "")
{
string baseurl = "http://sms.softhunters.in/pushsms.php?username=India Ltd.&password=293908&sender=Avyukta&to=" + MobileNo + "&message=" + smsMessage + "";
//string baseurl = "http://sms.creativeinfovision.in/pushsms.php?username=Creativeinfovision&password=your_password&sender=9829606976&to=9461816878&message=Hello";
Stream data = client.OpenRead(baseurl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
}
}
catch (Exception ex)
{
}
-----------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
string smsMessage = "Dear Customer Congratulations!!!," + "\r";
smsMessage += "call on 91-98-220-12345 or mail @ ccare.mh@idea.adityabirla.com visit @ http://www.ideacellular.com " + "\r";
//string MobileNo = txt_telephone.Text.Trim();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
WebClient client = new WebClient();
string no = "9887901185";
if (no != "")
{
string baseurl = "http://sms.softhunters.in/pushsms.php?username=SSMTPL&password=529670&sender=SSMTPL&to=" + no + "&message=" + smsMessage + "";
Stream data = client.OpenRead(baseurl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
}
}
-----------------------------------------
ON logic.Registration_Entry Time---->
-------------------------------------------
sendsms();
public void sendsms()
{
string smsMessage = "Welcome In PinkCity Gold Trading(P.)Ltd." + "\r";
smsMessage += "Your-UserID:" + usernewId + "\r";
smsMessage += "Your-SponsorID:" + sponsorid + "\r";
smsMessage += "Your-Password:" +Session["pwd"].ToString();
string MobileNo = txt_telephone.Text.Trim();
//HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
WebClient client = new WebClient();
// string baseurl = " http://sms.ziindia.com/sendurl.asp?user=20008672&pwd=12345&mobileno=9828437743&msgtext=hello h r u";
if (MobileNo != "")
{
string baseurl = "http://sms.softhunters.in/pushsms.php?username=Pinkcity Gold&password=264966&sender=Pinkcity&to=" + MobileNo + "&message=" + smsMessage + "";
//string baseurl = "http://sms.creativeinfovision.in/pushsms.php?username=Creativeinfovision&password=your_password&sender=9829606976&to=9461816878&message=Hello";
Stream data = client.OpenRead(baseurl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
}
}
--------------------------------------------------------------------
SMS Sending Code More than one Person
------------------------------------>
using connection_layer;
using TestWeb;
using System.IO;
using System.Net.Mail;
using System.Web.Services;
using System.Net;
public partial class Admin_Sukh_SMS_Gateway : System.Web.UI.Page
{
cls_connection con = new cls_connection();
DataSet ds = new DataSet();
DataSet dsddl = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
dsddl = con.select_data_ds("SELECT MainID, Telephone FROM EndUserAddress");
ddl_UseID.DataSource = dsddl;
ddl_UseID.DataTextField = "MainID";
ddl_UseID.DataValueField = "Telephone";
ddl_UseID.DataBind();
}
catch (Exception ex)
{
}
mul.ActiveViewIndex = 0;
}
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "0")
{
mul.ActiveViewIndex = 1;
}
else
mul.ActiveViewIndex = 2;
}
protected void btn_send_2all_Click(object sender, EventArgs e)
{
try
{
ds = con.select_data_ds("SELECT Telephone FROM EndUserAddress");
}
catch (Exception ex)
{
}
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
WebClient client = new WebClient();
string smsMessage = txt_usermessage.Text;
for (int i = 0; i <ds.Tables[0].Rows.Count; i++)
{
string MobileNo = ds.Tables[0].Rows[i][0].ToString();
if (MobileNo != "")
{
string baseurl = "http://sms.softhunters.in/pushsms.php?username=SSMTPL&password=529670&sender=SSMTPL&to=" + MobileNo + "&message=" + smsMessage + "";
Stream data = client.OpenRead(baseurl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
}
}
string prompt = "<script>$(document).ready(function(){{$.prompt('{0}!');}});</script>";
string message = string.Format(prompt, "Message Has been Sent to the All Users. ");
ClientScript.RegisterStartupScript(typeof(Page), "message", message);
}
protected void btn_back_Click(object sender, EventArgs e)
{
mul.ActiveViewIndex = 0;
}
protected void btn_send_Click(object sender, EventArgs e)
{
try
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
WebClient client = new WebClient();
string smsMessage = txt_send.Text;
string MobileNo = ddl_UseID.SelectedValue.ToString();
if (MobileNo != "")
{
string baseurl = "http://sms.softhunters.in/pushsms.php?username=SSMTPL&password=529670&sender=SSMTPL&to=" + MobileNo + "&message=" + smsMessage + "";
Stream data = client.OpenRead(baseurl);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
string prompt = "<script>$(document).ready(function(){{$.prompt('{0}!');}});</script>";
string message = string.Format(prompt, "Message Has been Sent to the User. ");
ClientScript.RegisterStartupScript(typeof(Page), "message", message);
}
}
catch (Exception ex)
{
}
}
}
----------------------------------------------------------------------------
copy files in c# asp.net
const int BUFFSIZE = 1024;
Stream instream = File.OpenRead(Server.MapPath("images/login_icon.png"));
Stream outstream = File.OpenWrite(Server.MapPath("images/israr.png"));
byte[] buffer = new Byte[BUFFSIZE];
int numbytes;
while ((numbytes=instream.Read(buffer,0,BUFFSIZE)) > 0)
{
outstream.Write(buffer,0,numbytes);
}
instream.Close();
outstream.Close();
Stream instream = File.OpenRead(Server.MapPath("images/login_icon.png"));
Stream outstream = File.OpenWrite(Server.MapPath("images/israr.png"));
byte[] buffer = new Byte[BUFFSIZE];
int numbytes;
while ((numbytes=instream.Read(buffer,0,BUFFSIZE)) > 0)
{
outstream.Write(buffer,0,numbytes);
}
instream.Close();
outstream.Close();
unique value in database, uniqueidentifier , unique value in sql server
DECLARE @myid uniqueidentifier
SET @myid = NEWID()
PRINT 'Value of @myid is: '+ CONVERT(varchar(40), @myid)
------------------------------------
CREATE TABLE cust
(
CustomerID uniqueidentifier NOT NULL
DEFAULT newid(),
Company varchar(30) NOT NULL,
ContactName varchar(60) NOT NULL,
Address varchar(30) NOT NULL,
City varchar(30) NOT NULL,
StateProvince varchar(10) NULL,
PostalCode varchar(10) NOT NULL,
CountryRegion varchar(20) NOT NULL,
Telephone varchar(15) NOT NULL,
Fax varchar(15) NULL
)
GO
-- Inserting data into cust table.
INSERT cust
(CustomerID, Company, ContactName, Address, City, StateProvince,
PostalCode, CountryRegion, Telephone, Fax)
VALUES
(NEWID(), 'Wartian Herkku', 'Pirkko Koskitalo', 'Torikatu 38', 'Oulu', NULL,
'90110', 'Finland', '981-443655', '981-443655')
Friday, 17 May 2013
How to use DataView ToTable method to create a new DataTable in ado.net
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
dt.TableName = "Books";
DataColumn dc1 = new DataColumn();
dc1.ColumnName = "BookID";
dc1.DataType = typeof(int);
dc1.AllowDBNull = false;
dc1.Unique = true;
DataColumn dc2 = new DataColumn();
dc2.ColumnName = "Category";
dc2.DataType = typeof(string);
DataColumn dc3 = new DataColumn();
dc3.ColumnName = "BookName";
dc3.DataType = typeof(string);
DataColumn dc4 = new DataColumn();
dc4.ColumnName = "Author";
dc4.DataType = typeof(string);
dt.Columns.AddRange(new DataColumn[] { dc1, dc2, dc3, dc4 });
dt.Rows.Add(new object[] { 1, "iPhone", "iPhone User Interface Cookbook: RAW", "Cameron Banga" });
dt.Rows.Add(new object[] { 2, "MySQL", "MySQL 5.1 Plugin Development", "Andrew Hutchings, Sergei Golubchik" });
dt.Rows.Add(new object[] { 3, "MySQL", "MySQL Admin Cookbook", "Daniel Schneller, Udo Schwedt" });
dt.AcceptChanges();
Label1.Text = "Source DataTable";
GridView1.DataSource = dt.DefaultView;
GridView1.DataBind();
//this line create a new DataView
DataView dView = new DataView(dt);
dView.RowFilter = "Category = 'MySQL'";
Label2.Text = "Here we create a new DataView<br />" +
"and set the RowFilter (Category = 'MySQL')";
GridView2.DataSource = dView;
GridView2.DataBind();
//this line create a new DataTable from DataView
DataTable dt2 = dView.ToTable();
Label3.Text = "Here we create a new DataTable from DataView";
GridView3.DataSource = dt2;
GridView3.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to use DataView ToTable method to create a new DataTable in ado.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
How to use DataView ToTable method
<br /> to create a new DataTable in ado.net
</h2>
<hr width="450" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
Font-Italic="true"
>
</asp:Label>
<asp:GridView
ID="GridView1"
runat="server"
BorderColor="Snow"
ForeColor="Snow"
Width="600"
Font-Names="Courier"
>
<HeaderStyle BackColor="DarkSlateBlue" Height="30" />
<RowStyle BackColor="MediumVioletRed" />
<AlternatingRowStyle BackColor="PaleVioletRed" />
</asp:GridView>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
Font-Italic="true"
>
</asp:Label>
<asp:GridView
ID="GridView2"
runat="server"
BorderColor="Snow"
ForeColor="Snow"
Width="600"
Font-Names="Courier"
>
<HeaderStyle BackColor="DarkSlateBlue" Height="30" />
<RowStyle BackColor="MediumVioletRed" />
<AlternatingRowStyle BackColor="PaleVioletRed" />
</asp:GridView>
<br />
<asp:Label
ID="Label3"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
Font-Italic="true"
>
</asp:Label>
<asp:GridView
ID="GridView3"
runat="server"
BorderColor="Snow"
ForeColor="Snow"
Width="600"
Font-Names="Courier"
>
<HeaderStyle BackColor="DarkSlateBlue" Height="30" />
<RowStyle BackColor="MediumVioletRed" />
<AlternatingRowStyle BackColor="PaleVioletRed" />
</asp:GridView>
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Populate GridView"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
dt.TableName = "Books";
DataColumn dc1 = new DataColumn();
dc1.ColumnName = "BookID";
dc1.DataType = typeof(int);
dc1.AllowDBNull = false;
dc1.Unique = true;
DataColumn dc2 = new DataColumn();
dc2.ColumnName = "Category";
dc2.DataType = typeof(string);
DataColumn dc3 = new DataColumn();
dc3.ColumnName = "BookName";
dc3.DataType = typeof(string);
DataColumn dc4 = new DataColumn();
dc4.ColumnName = "Author";
dc4.DataType = typeof(string);
dt.Columns.AddRange(new DataColumn[] { dc1, dc2, dc3, dc4 });
dt.Rows.Add(new object[] { 1, "iPhone", "iPhone User Interface Cookbook: RAW", "Cameron Banga" });
dt.Rows.Add(new object[] { 2, "MySQL", "MySQL 5.1 Plugin Development", "Andrew Hutchings, Sergei Golubchik" });
dt.Rows.Add(new object[] { 3, "MySQL", "MySQL Admin Cookbook", "Daniel Schneller, Udo Schwedt" });
dt.AcceptChanges();
Label1.Text = "Source DataTable";
GridView1.DataSource = dt.DefaultView;
GridView1.DataBind();
//this line create a new DataView
DataView dView = new DataView(dt);
dView.RowFilter = "Category = 'MySQL'";
Label2.Text = "Here we create a new DataView<br />" +
"and set the RowFilter (Category = 'MySQL')";
GridView2.DataSource = dView;
GridView2.DataBind();
//this line create a new DataTable from DataView
DataTable dt2 = dView.ToTable();
Label3.Text = "Here we create a new DataTable from DataView";
GridView3.DataSource = dt2;
GridView3.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to use DataView ToTable method to create a new DataTable in ado.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
How to use DataView ToTable method
<br /> to create a new DataTable in ado.net
</h2>
<hr width="450" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
Font-Italic="true"
>
</asp:Label>
<asp:GridView
ID="GridView1"
runat="server"
BorderColor="Snow"
ForeColor="Snow"
Width="600"
Font-Names="Courier"
>
<HeaderStyle BackColor="DarkSlateBlue" Height="30" />
<RowStyle BackColor="MediumVioletRed" />
<AlternatingRowStyle BackColor="PaleVioletRed" />
</asp:GridView>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
Font-Italic="true"
>
</asp:Label>
<asp:GridView
ID="GridView2"
runat="server"
BorderColor="Snow"
ForeColor="Snow"
Width="600"
Font-Names="Courier"
>
<HeaderStyle BackColor="DarkSlateBlue" Height="30" />
<RowStyle BackColor="MediumVioletRed" />
<AlternatingRowStyle BackColor="PaleVioletRed" />
</asp:GridView>
<br />
<asp:Label
ID="Label3"
runat="server"
Font-Size="Large"
ForeColor="DodgerBlue"
Font-Italic="true"
>
</asp:Label>
<asp:GridView
ID="GridView3"
runat="server"
BorderColor="Snow"
ForeColor="Snow"
Width="600"
Font-Names="Courier"
>
<HeaderStyle BackColor="DarkSlateBlue" Height="30" />
<RowStyle BackColor="MediumVioletRed" />
<AlternatingRowStyle BackColor="PaleVioletRed" />
</asp:GridView>
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Populate GridView"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
Subscribe to:
Posts (Atom)