sql c#
C-#入门经典(第三版).pdf
using System;
using System.Data;
using System.Data.SqlClient;
namespace My_Student
{
static class Program
{
static void Main()
{
//连接字符串,连接本地的MS SQL Server服务器
string connString = "data source=MICROSOF-84BB45;persist security info=False;initial catalog=MyDB;integrated security=SSPI;";
//SQL语句,删除记录
string sqlString = "delete from Courses where CourseNo='001'";
//建立连接对象
SqlConnection conn = new SqlConnection(connString);
conn.Open();//打开连接
//建立数据命令对象
SqlCommand cmd = new SqlCommand(sqlString, conn);
//执行命令,返回影响的行数
int rowsReturned = cmd.ExecuteNonQuery();
Console.WriteLine("{0} 记录已删除", rowsReturned);
MessageBox.Show("数据库更新成功!!");
conn.Close();//关闭连接
}
}
}
try
&nb
相关文档:
1、检查是否有非法字符
public static boolean sql_inj(String str)
{
String inj_str = "'|and|exec|insert|select|delete|update|
count|*|%|chr|mid|master|truncate|char|declare|;|or|-|+|,";
//这里的东西还可以自己添加
String[] inj_stra=inj_str.split("\\|");
for ......
记取记录集
create procedure getArticle
as
select * from Article_Content
GO
asp.net 调用方法
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = Data.Connstr();
Conn.Open();
......
[code]declare @startdt datetime
declare @enddt datetime
select @startdt='2009-12-03',@enddt='2009-12-05'
select * from tb
where 开始日期 between @startdt and @enddt
or 结束日期 between @startdt and @enddt
or @startdt between 开始日期 and 结束日期
or @enddt between 开始日期 and ......