Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

C# SQLÊý¾Ý¿â²Ù×÷ͨÓÃÀà


C# SQLÊý¾Ý¿â²Ù×÷ͨÓÃÀà
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace Framework.DataBase
{
///
/// ͨÓÃÊý¾Ý¿âÀà
///
public class DataBase
{
private string ConnStr = null;
public DataBase()
{
   ConnStr = ConfigurationSettings.AppSettings["ConnStr"];
}
public DataBase(string Str)
{
   try
   {
    this.ConnStr = Str;
   }
   catch(Exception ex)
   {
    throw ex;
   }
}
///
/// ·µ»Øconnection¶ÔÏó
///
///
public SqlConnection ReturnConn()
{
   SqlConnection Conn = new SqlConnection(ConnStr);
   Conn.Open();
   return Conn;
}
public void Dispose(SqlConnection Conn)
{
   if(Conn!=null)
   {
    Conn.Close();
    Conn.Dispose();
   }
}
///
/// ÔËÐÐSQLÓï¾ä
///
///
public void RunProc(string SQL)
{
   SqlConnection Conn;
   Conn = new SqlConnection(ConnStr);
   Conn.Open();
   SqlCommand Cmd ;
   Cmd = CreateCmd(SQL, Conn);
   try
   {
    Cmd.ExecuteNonQuery();
   }
   catch
   {
    throw new Exception(SQL);
   }
   Dispose(Conn);
   return;
}   
///
   /// ÔËÐÐSQLÓï¾ä·µ»ØDataReader
///
    ///
    /// SqlDataReader¶ÔÏó.
public SqlDataReader RunProcGetReader(string SQL)
{
   SqlConnection Conn;
   Conn = new SqlConnection(ConnStr);
   Conn.Open();
   SqlCommand Cmd ;
   Cmd = CreateCmd(SQL, Conn);
   SqlDataReader Dr;
   try
   {
    Dr = Cmd.ExecuteReader(CommandBehavior.Default);
   }
catch


Ïà¹ØÎĵµ£º

SQL SERVER×Ö¶ÎÀàÐÍ˵Ã÷

 
bit£º0»ò1µÄÕûÐÍÊý×Ö
int£º´Ó-2^31(-2,147,483,648)µ½2^31(2,147,483,647)µÄÕûÐÍÊý×Ö
smallint£º´Ó-2^15(-32,768)µ½2^15(32,767)µÄÕûÐÍÊý×Ö
tinyint£º´Ó0µ½255µÄÕûÐÍÊý×Ö

decimal£º´Ó-10^38µ½10^38-1µÄ¶¨¾«¶ÈÓëÓÐЧλÊýµÄÊý×Ö
numeric£ºdecimalµÄͬÒå´Ê

money£º´Ó-2^63(-922,337,203,685,477.580 ......

ASP.NETºÍSQL SERVERÖÐʹÓÃÊÂÎñʾÀý

1£¬SqlServer´æ´¢¹ý³ÌµÄÊÂÎñ´¦Àí
Ò»ÖֱȽÏͨÓõijö´í´¦ÀíµÄģʽ´ó¸ÅÈçÏ£º
Create procdure prInsertProducts
(
 @intProductId int,
 @chvProductName varchar(30),
 @intProductCount int
)
AS
Declare @intErrorCode int
Select @intErrorCode=@@Error
Begin transaction
 if @intError ......

SQL²éѯ ÖØ¸´¼Ç¼

1¡¢²éÕÒ±íÖжàÓàµÄÖØ¸´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö×ֶΣ¨peopleId£©À´ÅжÏ
select * from people
where peopleId in (select   peopleId  from   people  group  by   peopleId  having  count(peopleId) > 1)
2¡¢É¾³ý±íÖжàÓàµÄÖØ¸´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö× ......

sql update Ó÷¨

½«b±íÖÐcallerÁеÄÖµ²åÈëa±íÖÐcallÁÐÖС£
 create table a
(
 fid int,
 call varchar(20),
 age int
)
create table b
(
 fid int,
 caller varchar(20),
 parentId int
)
select * from a
select * from b
insert into a values(1,null,19)
insert into a values(2,n ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ