关于Sql Server 判断表与否(DataGridView导入数据库,判断是否已经有此表)

  最近做Excel 导入导出Sql

//查询数据库,如果表存在则删除,否则创建                   

 // string strSql = string.Format("if exists (select * from sysobjects where name ='" + SheetSet[3] + "')drop table " + SheetSet[3] + " else create table " + SheetSet[3] + "(", fileName);

  //如果表存在,则输出存在,否则创建 

string strSql = string.Format("if  exists(select * from sysobjects where name = '" + SheetSet[3] + "')print '存在'if not exists(select * from sysobjects where name = '" + SheetSet[3] + "')create table " + SheetSet[3] + "(", fileName);


" + SheetSet[3] + "  这个是表名

猜你喜欢

转载自blog.csdn.net/zhangzhenjie235/article/details/80083782