當前位置:首頁 » 編程語言 » sql封裝問題
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql封裝問題

發布時間: 2022-06-11 01:04:18

1. 如何將sql資料庫連接封裝到DLL中

使用C#生成dll文件並調用
一、創建dll文件:

例如生成一個md5編碼判斷狀態的文件,即,輸入一個字元串(string A)和一個32位md5編碼(string B),判斷此字元串A對應的32位md5編碼是否與B相等,如果相等返回true,否則返回false。

打開VS 2005,「文件」--》「新建」--「項目」,選擇「Windows 控制項庫」,命名後點擊「確定」,在「UserControl1.cs」中輸入以下代碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

using System.Text;
using System.Security.Cryptography;

namespace md5
{
public partial class Program : UserControl
{
#region MD5 32位加密:GetMd5Str32
/// <summary>
/// 32位MD5加密
/// </summary>
/// <param name="strSource">待加密字串</param>
/// <returns>加密後的字串</returns>
public static string GetMd5Str32(string strSource)
{
byte[] bytes = Encoding.ASCII.GetBytes(strSource);
byte[] hashValue = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytes);
StringBuilder sb = new StringBuilder();

for (int i = 0; i < 16; i++)
{
sb.Append(hashValue[i].ToString("x2"));
}

return sb.ToString().ToUpper();
}
#endregion

#region 核對md5編碼是否一致:CheckMd5String()

/// <summary>
/// 核對md5編碼是否一致
/// </summary>
/// <param name="ConvertString"></param>
/// <returns>如果一致返回true,否則返回false</returns>
///
public static bool CheckMd5String(string str1, string str2)
{
string md5String = str1; //需要驗證的字元串
string md5DbString = str2; //需要核對的32位md5編碼

int result = string.Compare(md5.Program.GetMd5Str32(str1), md5DbString, true);
if (result == 0)
{
return true;
}
else
{
return false;
}
}
#endregion
}
}

修改「UserControl1.Designer.cs」中的命名空間為「md5」,方法為「Program」,即可生成dll文件。

在...\bin\Debug文件假下,可以找到相應的dll文件。

二、部署dll流程:

首先把dll文件放到應用程序...\bin\Debug\下;
然後在解決方案中添加引用:右鍵滑鼠-->添加引用-->瀏覽-->選擇dll放置路徑後點擊「確定」。
注意:要在應用文件頭處使用using md5;命令。

測試應用程序代碼,如下:Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using md5;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string str1 = textBox1.Text.ToString();
string md5String = textBox2.Text.ToString();

textBox3.Text = md5.Program.GetMd5Str32(str1);
textBox4.Text = md5.Program.CheckMd5String(str1, md5String).ToString();

}

private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

2. mybatis sql屬性用sql標簽封裝出問題了 應該怎麼改

username=#{1},password=#{2} where id=#{0}這些代碼寫的有問題,應該是對應的UserInfo裡面的屬性名,如useName,password,id等。

3. c# sqlDataReader 封裝調用問題(調用出錯 錯誤提示如圖)

///
<summary>
///
執行查詢語句,返回SqlDataReader
(
注意:調用該方法後,一定要對SqlDataReader進行Close
)
///
</summary>
///
<param
name="strSQL">查詢語句</param>
///
<returns>SqlDataReader</returns>
public
static
SqlDataReader
ExecuteReader(string
strSQL)
{
SqlConnection
connection
=
new
SqlConnection(connectionString);
SqlCommand
cmd
=
new
SqlCommand(strSQL,
connection);
try
{
connection.Open();
SqlDataReader
myReader
=
cmd.ExecuteReader(CommandBehavior.CloseConnection);
return
myReader;
}
catch
(System.Data.SqlClient.SqlException
e)
{
throw
e;
}
}
上面的代碼是微軟的資料庫操作類中此部分內容的寫法
您可以參考
您的問題我感覺應該是你外部程序的問題
看您此處的代碼
暫時還沒發現問題

4. 9.6 如何封裝sql 資料庫命令舉例

做成 存儲過程
create procere sp_procere --創建存儲過程
(@key varchar(10)) --設置傳遞的參數(可以沒有)
as
begin
--需封裝的sql語句
end
運行該存儲過程
exec sp_procere 參數

5. hibernate 用sql完成多表查詢的結果集如何封裝

將student,class關聯創建一個視圖,然後createSQLQuery("查詢視圖")
.setResultTransformer(Transformers.aliasToBean(視圖VO.class))
.list();
這樣就萬事大吉了

6. 大神們,膝蓋奉上了~sql server如何將多條語句封裝為一個存儲過程

可以的,你把軟體發過來,我幫你研究一下怎麼封裝

7. Sql2000資料庫怎樣封裝

直接對資料庫封裝?好象不行吧,最多你把代碼封裝,資料庫里把許可權設置好,別人也直接進不來,然後在對一些存儲過程加密.

8. mybatis是如何將sql執行結果封裝為目標對象並返回的都有哪些映射形式

是寫一個resultmap然後指明欄位和屬性映射關系就行

9. sql2005:如何封裝一些重用性高的sql語句塊

把一些經常用到的存儲過程放到一個程序包裡面,相當於java裡面的utils包,以後要調用的時候,直接包名.存儲過程就行了。


比如,現在我建立一個最簡單的工具包:


createorreplacepackagePKG_COMM_UTILSis
procereconsoleInfo(MSGINvarchar2);
endPKG_COMM_UTILS;createorreplacepackagebodyPKG_COMM_UTILSis
procereconsoleInfo(MSGINvarchar2)is
begin
dbms_output.put_line(MSG);
end;
endPKG_COMM_UTILS;


調用:

declare
begin
PKG_COMM_UTILS.consoleInfo('HelloWorld!');
end;

輸出:

Hello World !


不懂可以再問。

10. SQL將函數封裝到存儲過程,如何實現

思維混亂。沒有邏輯。做事要一件件來。不能這樣稀里糊塗。
第一步:創建函數:

Create function NeterCenter_ChangeChinese
(
@str nvarchar(4000)
)
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非漢字字元,返回原字元
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (
select top 1 PY
from
(
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC
)
else @word
end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
GO

--第二步:創建存儲過程,調用函數:

create PROCEDURE sp_GetIt
@str varchar(3000)--參數
AS
select dbo.NeterCenter_ChangeChinese(@str) OutStr

--第三步,使用過程
sp_GetIt '我是中國人'

master是系統資料庫,不要將你自己寫的腳步放到該庫,自己創建資料庫。