[csharp] <p>1. 连接本地数据库的语句 string str_conn = "server=.;database=Employees;Trusted_Connection=SSPI;";</p><p>2. 使用DataSet获取数据库返回的数据</p>
[csharp]
string str_conn = "server=.;database=Employees;Trusted_Connection=SSPI;";
string sql = string.Format(
"select * from Admin where LoginID='{0}' and Password='{1}'",
this.textBoxUser.Text = loginId, this.textBoxPas.Text = loginPwd);
SqlConnection sqlconn = new SqlConnection(str_conn);
sqlconn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql,str_conn);
DataSet ds1 = new DataSet();
sda.Fill(ds1);
int count = ds1.Tables[0].Rows.Count;
创建存储过程:
CREATE PROC[EDURE] 存储过程名
@参数1 数据类型 =默认值OUTPUT,
…… ,
@参数n 数据类型 =默认值 OUTPUT
AS
SQL语句
GO
T-sql
DECLARE @变量名 数据类型
SET @变量名=值
SELECT @变量名= 值
IF (条件)
BEGIN
语句1
语句2
……
END
ELSE
BEGIN
语句1;
语句2;
……
END
WHILE (条件)
BEGIN
语句1
语句2
……
BREAK
END
触发器:
CREATE TRIGGER trigger_name
ON table_name
[WITH ENCRYPTION]
FOR [DELETE,INSERT, UPDATE]
AS
T-SQL语句
GO
实例:
CREATE TRIGGER trig_transInfo
ON transInfo
FOR INSERT
AS
DECLARE @type char(4),@outMoney MONEY
DECLARE @myCardIDchar(10),@balance MONEY
SELECT @type=transType,@outMoney=transMoney,
@myCardID=cardIDFROM inserted
IF (@type='支取')
UPDATE bank SET currentMoney=currentMoney-@outMoney
WHERE cardID=@myCardID
ELSE
发表回复