首先,我在工程项目里建立以下几个文件夹:
然后看代码实现
1.创建数据库
create database article
CREATE TABLE [news] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[title] [char] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[content] [varchar] (8000) COLLATE Chinese_PRC_CI_AS NULL
,
[FilePath] [char] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
2.web.config配置数据库连接文件关键代码
<appSettings>
<add key='connectionstring'
value='server=.;uid=sa;pwd=;database=article'/>
</appSettings>
连接数据库类
using System;
using System.Data;
using System.Configuration;
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.Htm
Procedure TForm1.Button1Click(Sender: TObject);
Var
FormHwd, OKHandle, EDHwd1, EDHwd2: THandle;
Begin
FormHwd := FindWindow(nil, '用户登录'); //窗口名称
If FormHwd > 0 Then
Begin
OKHandle := FindWindowEx(FormHwd, 0,
PChar('TBitBtn'), Pchar('确定'));//按钮
EDHwd1 := FindWindowEx(FormHwd, 0,
PChar('TEdit'), nil);
SendMessage(EDHwd1, WM_SETTEXT, 255,
Longint(PChar('0')));
EDHwd2 := FindWindowEx(FormHwd, EDHwd1,
PChar('TEdit'), nil);
SendMessage(EDHwd2, WM_SETTEXT, 255,
Longint(PChar('jwc01')));
SendMessage(OKHandle,BM_CLICK,0,0);
End;
End;
delphi dbgrid 导出Excel表
///////// 利用剪贴板,速度很快!适合装有Excel的机器/////////////////////
USES Clipbrd,ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
i:Integer;
excelapp,sheet:Variant;
begin
// lbl2.Caption:=DateTimeToStr(Now);
str:='';
dbgrd1.DataSource.DataSet.DisableControls;
for i:=0 to
dbgrd1.DataSource.DataSet.FieldCount-1 do
str:=str+dbgrd1.DataSource.DataSet.fields[i].DisplayLabel+char(9);
str:=str+#13;
dbgrd1.DataSource.DataSe
string strOrderID =
this.textBox1.Text.Trim().ToString();
string strCustomerID =
this.textBox2.Text.Trim().ToString();
//被SQL注入的拼SQL的句子是这么写的
//string strSql = 'Select * from [Orders] Where OrderId = '' +
strOrderID + '' AND CustomerID = '' + strCustomerID +
''';
//防止SQL注入的拼SQL的句子是这么写的
string
strSql = 'Select * from [Orders] Where OrderId = @strOrderID
AND CustomerID = @strCustomerID';
//加sqlParameter变量
SqlCommand myCommand = new SqlCommand(strSql, con);&nbs
一,验证方法
/// <summary>
///SQL注入过滤
/// </summary>
/// <param name='InText'>要过滤的字符串</param>
/// <returns>如果参数存在不安全字符,则返回true</returns>
public static bool SqlFilter2(string InText)
{
string
word='and|exec|insert|select|delete|update|chr|mid|master|or|truncate|char|declare|join';
if(InText==null)
return false;
foreach(string i in word.Split('|'))
{
if((InText.ToLower().IndexOf(i+'
')>-1)||(InText.ToLower().IndexOf(' '+i)>-1))
{
return true;
}
}
return false;
}
二,Global.asax 事件
/// <summary>
/// 当有数据时交时,触发事件
QRBand 上放置N个QRLabel 不设置分栏.
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
QuickRep1.Preview;
end;
procedure TForm1.QuickRep1NeedData(Sender: TObject; var
MoreData: Boolean);
var
i:integer;
begin
MoreData := True;
if adoquery1.Eof then
MoreData := False;
QRLabel1.Caption:='';
QRLabel2.Caption:='';
QRLabel3.Caption:='';
QRLabel4.Caption:='';
QRLabel5.Caption:='';
QRShape2.Pen.Color:=clwhite;
for I:= 1
to 5 do
begin
if adoquery1.Eof then break;
case i of
1:
QRLabel1.Caption:=
adoquery1.FieldByName('OA_LoginID').AsString;
创建子窗口(MDI)
Procedure Tmain_form.OpenForm(FormClass: TFormClass; Var fm;
AOwner: TComponent);
Var
i: integer;
Child: TForm;
Begin
For i := 0 To Screen.FormCount - 1 Do
If Screen.Forms[i].ClassType = FormClass
Then
Begin
Child := Screen.Forms[i];
If Child.WindowState =
wsMinimized Then
ShowWindow(Child.Handle, SW_SHOWNORMAL)
Else
ShowWindow(Child.Handle, SW_SHOWNA);
If (Not Child.Visible) Then
Child.Visible := true;
Child.BringToFront;
Child.Setfocus;
TForm(fm) := Child;
&nbs
在SERVER面板上选择WordDocument 和WordApplication 组件
Procedure Tform1.ConnectWord;
Begin
Try
WordApplication.Connect;
Except
MessageDlg('Word可能没有安装!', mtError, [mbOk],
0);
Abort;
End;
Try
WordApplication.Visible := True;
WordApplication.caption := 'Delphi
automation';
Except
Try
quitword;
WordApplication.Connect;
WordApplication.Visible :=
True;
WordApplication.caption :=
'Delphi automation';
Except
Abort;
End;
End;
End;
Procedu
<table cellspacing='1' cellpadding='1' width='712' border='0'
align='center'>
</table>
<marquee style='WIDTH: 220px; HEIGHT: 250px' direction='up'
scrolldelay='200'
onmouseover='this.stop()'onmouseout='this.start()'>
<asp:GridView id='GVItemOne' runat='server' Width='223px'
Font-Size='9pt' Height='39px' ForeColor='RoyalBlue' CellPadding='4'
DataKeyNames='ID' GridLines='None' PageSize='15'>
<FooterStyle BackColor='#507CD1' ForeColor='White'
Font-Bold='True'></FooterStyle>
&l