随笔分类 -  10SqlServer

摘要:1,连接字符串Server=localhost;port=3306;User ID=root;password=admin;database=;charset=utf8;Allow User Variables=True2,mysql str_to_date字符串转换为日期select str_to... 阅读全文
posted @ 2015-10-22 15:15 金河 阅读(173) 评论(0) 推荐(0) 编辑
摘要:1,mysql报Fatal error encountered during command execution的解决办法连接字符串里加上Allow User Variables=True解决。2,null值比较null和任何值都不能比较null只能用is null 或者is not null 来判... 阅读全文
posted @ 2015-10-15 17:27 金河 阅读(185) 评论(0) 推荐(0) 编辑
摘要:1,查找mysql 数据库 自动 添加 序号 字段列1,2,3,4select (@rowNO := @rowNo+1) AS rowno,ip,startcount from (SELECT ip,startcount FROM client where appname='1' ) a,(se... 阅读全文
posted @ 2015-10-15 15:40 金河 阅读(283) 评论(0) 推荐(0) 编辑
摘要:下面是分页存储过程:create proc [dbo].[proc_value_page]@pageIndex int,@pageSize int,@pageCount int outputasdeclare @totalRecord intselect @totalRecord=count(*) from dbo.spt_valuesset @pageCount=ceiling(@totalRecord*1.0/@pageSize)select * from(select row_number() over(order by number asc) as num,* from dbo.sp. 阅读全文
posted @ 2012-11-22 21:23 金河 阅读(963) 评论(0) 推荐(0) 编辑
摘要:以前只知道分页,但是不知道如何实现的,曾经有次面试让我实现分页,搜了很久,只是知道有个top,但是不懂得原理,没有搞出来。今天在学习link to ef时,使用到了一条语句就把分页搞定了,然后我才明白了原理。 1,下面是link to ef中使用到的分页方法:link分页 //创建数据库实体 using (studentEntities stuEntity = new studentEntities()) { int skipPage=2;//要跳过多少页,指定2也就是跳到第3页 ... 阅读全文
posted @ 2012-08-13 18:27 金河 阅读(6970) 评论(0) 推荐(3) 编辑
摘要:1 创建数据库--系统数据库master中保存了所有本地数据库的名字use mastergoif exists(select * from sysdatabases where name='student')drop database student --如果数据库存在就删除gocreate database student --数据库名on( --使用的是小括号name='student', --数据库逻辑名filename='E:\Data\student.mdf', --数据库文件存... 阅读全文
posted @ 2012-08-11 18:31 金河 阅读(374) 评论(0) 推荐(0) 编辑
摘要:在我们编写数据访问层DAL时,常常需要编写一个SQLHelper类,方便其他的数据库表类调用,下面就是一个实现了可以传递sql语句来增删改查得类:using System;using System.Collections.Generic;using System.Text;using System.Data.SqlClient;using System.Data;using System.Configuration;namespace DAL{ public class SQLHelper { private SqlConnection conn = null; ... 阅读全文
posted @ 2012-07-11 17:42 金河 阅读(363) 评论(0) 推荐(0) 编辑
摘要:1、(1)此处只允许使用常量、表达式或变量。不允许使用列名。错误原因:string sql = "insert into category(name) values(" + caName + ")";//错误,应该在caName上加单引号string sql = "insert into category(name) values('" + caName + "')"; //修改后(2)新建网站,新建类库,但是打开后类库“无法生成”。解决:打开----->网站------>选择web网站 阅读全文
posted @ 2012-07-11 11:24 金河 阅读(526) 评论(0) 推荐(0) 编辑
摘要:在编写程序中,我们可能遇到诸如查询最热门的5篇文章或返回满足条件的n条记录的情况,在SQL语言中,可以使用TOP关键字来实现。 TOP关键字在SQL语言中用来限制返回结果集中的记录条数,其使用方法有两种形式,下面做以详细的介绍:(1)返回确定数目的记录个数语法格式: SELECT TOP n <列名表> FROM <表名> [查询条件]其中,n为要返回结果集中的记录条数(2)返回结果集中指定百分比的记录数语法格式: SELECT TOP n PERCENT <列名表> FROM <表名> [查询条件]其中,n为所返回的记录数所占结果集中记录数目的 阅读全文
posted @ 2012-07-09 15:55 金河 阅读(101767) 评论(1) 推荐(6) 编辑
摘要:1、将两个表连接时,如果要显示具有相同列的属性,要指定是哪个表的列:string sql = "select 姓名=sName,学号=studentInfo.sNo,语文=sChinese from studentInfo join studentScore on studentScore.sNo=studentInfo.sNo ";2,查询某列是否有相同的值:(1)按照姓名分组(就是查询的那一列),查找出个数大于1的姓名和个数。select name,count(*) from spt_values group by namehaving count(*)>1;3 阅读全文
posted @ 2012-06-10 11:30 金河 阅读(294) 评论(0) 推荐(0) 编辑
摘要:断开式操作数据库使用DataSet和SqlDataAdapter,通过adapter的fill方法将数据库中的数据填充到数据集中,通过update方法将数据集中的数据更新到数据库中。 1 对于Fill(DataSet ds,String dtName),将数据填充到数据集ds的表dtName中,dtName是数据集中的表名,与数据库中表名无关,但是通常相同。 2 对于Update(DataTable dt)更新某个数据表需要三步:(1)添加一行:DataRow row = ds.Tables["studentInfo"].NewRow();//(1)新建一行;(2)指定数据 阅读全文
posted @ 2012-06-09 18:05 金河 阅读(783) 评论(0) 推荐(0) 编辑
摘要:写连接字符串时需要制定server(连接到哪一台电脑),database(连接到哪一个数据库)一、使用SqlConnection对象时,需要指定连接字符串,下面是相关介绍:uid(用户名),pwd(登陆密码),Integrated Security(连接协议true或SSPI),Initial Catalog(连接到的数据库).下面是一些实例:1 string connectionString = "server = 304b2;database = students; uid = sa; pwd = "; //304b2是本机名字,还可以是用local或 . 或 127. 阅读全文
posted @ 2012-06-09 16:26 金河 阅读(339) 评论(0) 推荐(0) 编辑
摘要:1、创建数据库 Create DataBase studentson( Name='students_data', --数据文件的逻辑名 FileName='D:\students_data.mdf', --数据文件的实际名 Size=10Mb, --数据文件初始大小 FileGrowth=15% --数据文件的增长率)Log on( Name='students_log', --日志文件的逻辑名 FileName='D:\students_log.ldf', --日志文件... 阅读全文
posted @ 2012-06-05 10:29 金河 阅读(332) 评论(0) 推荐(0) 编辑
摘要:1有时候SqlCommand中的sql语句中要用到变量,如:string commandText = "UPDATE Sales.Store SET Demographics = @demographics " + "WHERE CustomerID = @ID;";这个时候可以向SqlCommand对象中添加变量,有多种方法:(1)command.Parameters.Add("@ID", SqlDbType.Int);//增加sql中的参数command.Parameters["@ID"].Value = cu 阅读全文
posted @ 2012-05-21 16:24 金河 阅读(318) 评论(0) 推荐(0) 编辑
摘要://获取连接字符串,不过要在"引用"中添加对Configuration的引用public static string GetConnStr(){ return system.Configuration.ConfigurationManager.AppSettings["ConnStr"];}2//获取连接对象,直接是打开过的 public static SqlConnection GetConn() { SqlConnection Conn = new SqlConnection(GetConnStr()); ... 阅读全文
posted @ 2012-05-20 16:26 金河 阅读(138) 评论(0) 推荐(0) 编辑
摘要:1(1) 如果使用System.Configuration.ConfigurationManager.AppSettings["ConnStr"];来得到连接字符串,必须:右击项目中的“引用",选择"添加引用",选择 System.Configuration。 阅读全文
posted @ 2012-05-20 16:20 金河 阅读(169) 评论(0) 推荐(0) 编辑