1 SET LANGUAGE ENGLISH
2 SET STATISTICS TIME ON
3 SET STATISTICS IO ON
4
5
6 PRINT 'Result of first Query'
7 Your first Query
8 PRINT 'Result of second Query'
9 Your second Query
Reference
1 SET LANGUAGE ENGLISH
2 SET STATISTICS TIME ON
3 SET STATISTICS IO ON
4
5
6 PRINT 'Result of first Query'
7 Your first Query
8 PRINT 'Result of second Query'
9 Your second Query
SET DATEFORMAT DMY
Note: DMY means Day-Month-Year, so you can use MDY or YDM, etc...
1 ALTER PROCEDURE [dbo].[CalculateSomething]
2 @myID INT
3 AS
4 BEGIN
5 DECLARE @myIDLocal INT
6
7 SET @myIDLocal = @myID -- If you this performance of query
8 -- will inctrease!
9 SELECT * FROM myTable WHERE ID = @myIDLocal
1
2 ReportDocument reportDocument = new ReportDocument();
3 ParameterField paramField = new ParameterField();
4 ParameterFields paramFields = new ParameterFields();
5 ParameterDiscreteValue paramDiscreteValue =
new ParameterDiscreteValue();
6
7 /***********************************/
8
9 paramField.Name = "@ID";
10 paramDiscreteValue.Value = textBox.Text;
11 paramField.CurrentValues.Add(paramDiscreteValue);
12 paramFields.Add(paramField);
13 CrystalReportViewer.ParameterFieldInfo = paramFields;
14
15 reportDocument.Load(Server.MapPath("Report.rpt"));
16 CrystalReportViewer1.ReportSource = reportDocument;
17 reportDocument.SetDatabaseLogon("myUsername", "myPassword",
18 "192.187.1.1", "myDatabase");
1 //Get session value:
2
3 int sessionValue = ((int)Context.Session.Contents["myValue"]);
4
5
6 //Set session value:
7
8 Context.Session.Add("mySessionValue", 1001);
1 ConfigurationManager.ConnectionStrings["MyConnectionString"]
.ConnectionString
How to create excel at ASP.NET?
How to make excel file at ASP web Page?
In the example belove we open a template Excel file, change it content
and save it as an other file.
You add
using Microsoft.Office.Interop.Excel;
directive and the rest is straight forward.
You must also add Microsoft.Office.Interop.Excel as reference from Add Reference.1 Sheets WRss = null;
2 _Worksheet WRws = null;
3
4 string baseFile = Server.MapPath(".") + "\\MyTemplate.xls";
5 string newFile = Server.MapPath(".") + "\\MyFile.xls";
6
7 Microsoft.Office.Interop.Excel.Application oExcel =
8 new Microsoft.Office.Interop.Excel.Application();
9
10 oExcel.Workbooks.Open(baseFile, Type.Missing, false,
11 Type.Missing, Type.Missing, Type.Missing,
12 Type.Missing, Type.Missing, Type.Missing,
13 Type.Missing, Type.Missing, Type.Missing,
14 Type.Missing, Type.Missing, Type.Missing);
15
16 WRss = (Sheets)oExcel.Worksheets;
17 WRws = (_Worksheet)(WRss.get_Item(1));
18
19 WRws.Cells.Font.Size = 12;
20
21 WRws.Cells[7, 3] = "Write Sometyhing";
22
23 if (System.IO.File.Exists(newFile))
24 System.IO.File.Delete(newFile);
25
26 oExcel.Workbooks[1].SaveAs(newFile, Type.Missing,
27 Type.Missing, Type.Missing, Type.Missing, false,
28 Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
29 Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
30
31 oExcel.Workbooks.Close();
32 oExcel.Quit();
33
34 Response.Clear();
35 Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
36 Response.AppendHeader("Content-disposition",
37 "attachment; filename=MyFile.xls");
38 Response.TransmitFile(newFile);
1 string newFile = Server.MapPath(".") + "\\MyFile.xls";
2 Response.Clear();
3 Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
4 Response.AppendHeader("Content-disposition", "attachment; filename=Hesabat.xls");
5 Response.TransmitFile(newFile);
1 SELECT
2 TABLE_SCHEMA,
3 TABLE_NAME,
4 OBJECTPROPERTY(object_id(TABLE_NAME),
5 N'IsUserTable') AS type
6
7 FROM
8
9 INFORMATION_SCHEMA.TABLES
1 string urlVar1 = Request.QueryString["var1"];
2 string urlVar2 = Request.QueryString["var2"];
1 string connectionString = "Data Source=DatabaseSERVER\SQLEXPRESS;Initial
Catalog=DatabaseName;Persist Security
Info=True;User ID=yourUserName;Password=yourPassword"
2
3 db myDatabaseObject = new db(connectionString);
4
5 DataSet myDataSet = new DataSet();
6
7 myDatabaseObject.GetDbData("SELECT * FROM TableName", myDataSet);
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.HtmlControls;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Data.SqlClient;
11 using System.Collections;
12
13 /// <summary>
14 /// Database class includes database operation methods.
15 /// </summary>
16 public class db
17 {
18 SqlConnection connection = null;
19 string query = "";
20 bool dbResult = false;
21 DataSet dataSet = null;
22 string[] tables = { "Table1", "Table2", "Table3", "Table4" };
23 enum dbTables: int
24 {
25 Table1,
26 Table2,
27 Table3,
28 Table4
29 }
30
31
32 public db(string connectionString)
33 {
34 connection = new SqlConnection(connectionString);
35 connection.Open();
36 }
37
38 public SqlConnection Connection
39 {
40 get
41 {
42 return connection;
43 }
44 set
45 {
46 connection = value;
47 }
48 }
49
50 public void CloseDbConnection()
51 {
52 connection.Close();
53 }
54
55 public bool GetDbData(string query, ref DataSet ds)
56 {
57 try
58 {
59 SqlCommand cmd = new SqlCommand();
60 cmd.CommandTimeout = 0;
61 cmd.Connection = connection;
62 cmd.CommandText = query;
63 cmd.CommandType = CommandType.Text;
64 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
65 {
66 ds = new DataSet();
67 da.Fill(ds);
68 cmd.Parameters.Clear();
69 }
70 return true;
71 }
72 catch
73 {
74 return false;
75 }
76 }
77
78 public bool WriteDbData(string query)
79 {
80 try
81 {
82 SqlCommand addCatCommand = new SqlCommand();
83 addCatCommand.Connection = connection;
84 addCatCommand.CommandText = query;
85 addCatCommand.ExecuteNonQuery();
86 return true;
87 }
88 catch
89 {
90 return false;
91 }
92 }
93 }
1 Response.Write(<script>alert('Hello')</script>);
1 Process pr = new Process();
2 pr.StartInfo.FileName = "notepad.exe";
3 pr.Start();
1 DECLARE @dummy VARCHAR(50)
2 DECLARE @myOutput VARCHAR(50)
3
4 DECLARE db_cursor CURSOR FOR
5 SELECT fieldName
6 FROM tableName
7
8 OPEN db_cursor
9 FETCH NEXT FROM db_cursor INTO @dummy
10
11 WHILE @@FETCH_STATUS = 0
12 BEGIN
13 SET @myOutput = @dummy
14 PRINT @myOutput
15 FETCH NEXT FROM db_cursor INTO @dummy
16 END
17
18 CLOSE db_cursor
19 DEALLOCATE db_cursor