Excel中数据导入到SQL Server数据库
using System.Data.SqlClient;
using System.Data.OleDb;
private void tsmiImportTeacherInfo_Click(object sender, EventArgs e)
{
DataSet ds;
if (ofdImport.ShowDialog()==DialogResult.OK)
{
ds = ImportExcel(this.ofdImport.FileName); //获得Excel
}
else
{
return;
}
int odr = 0;
SqlConnection cn = db.sqlconnection();
try
{
cn.Open();
string str = "insert into Teacher (TeacherId,Pwd,eachCourse,TeacherName) values(@TeacherId,@Pwd,@TeachCourse,@TeacherName)";
SqlCommand cmd = db.sqlcommand(str,cn);
int dsLength = ds.Tables[0].Rows.Count; //获得Excel中数据长度
&
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
在VS中写SQL语句的时候,千万万千要小心再小心,比如 说 数据类型的匹配, 单引号(这个能把人迷死)
where 子句中可千万不能有空格(当查询条件为字符串的时候能把你弄疯,我弄这个的时候都疯了几次了,什么都对就是查不出来,调试了N遍才发现。)不行了,吃饭去,再不吃看见活人都想咬了。 ......
SQL(结构化查询语言)注入,简单来说就是利用SQL语句在外部对SQL数据库进行查询,更新等动作。首先,数据库作为一个网站最重要的组件之一(如果这个网站有数据库的话),里面是储存着各种各样的内容,包括管理员的账号密码 ......
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)
删除表:
Drop table [表 ......