‘壹’ sql语句封装两个结果集,什么意思
用以个方法,接受sql语句处理后
赛选出来的数据~~
然后传给这个方法
方法将数据封装
在这个方法的集合中
‘贰’ 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是系统数据库,不要将你自己写的脚步放到该库,自己创建数据库。
‘叁’ 请教如何用C封装sql语句
假如用户输入的姓名和年龄值分别保存在变量name,age中: char sql_insert[200]; sprintf(sql_insert, "INSERT INTO table values('%s','%d');", name, age); mysql_query(&mysql_conn, sql_insert); 上述语句在执行完sprintf语句后,sql_insert...
‘肆’ 9.6 如何封装sql 数据库命令举例
做成 存储过程
create procere sp_procere --创建存储过程
(@key varchar(10)) --设置传递的参数(可以没有)
as
begin
--需封装的sql语句
end
运行该存储过程
exec sp_procere 参数
‘伍’ 如何将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();
}
}
}
‘陆’ 在C#中怎么将所有的sql语句打包成.dll文件或者其他 在C#程序中又怎么调用呢
我不明白 你是想生成DLL 还是调用?
如果是调用的话! 你只要把你生成好的DLL放到bin目录下! 然后在你的项目里 using 你的DLL名称 然后在项目里 实例化一下你的类名就可以了
‘柒’ 怎么把sql的数据库封装成CDatabaseAccess类
可以参考一下这个:
使用CDatabase类来读取Microsoft Access数据库,主要实现了以下功能:
从Microsoft Access 数据库读取数据
不使用ODBC数据源进行数据库连接
在List view控件中显示数据
// 以下是部分代码
void CReadDBDlg::OnRead()
{
// TODO: Add your control notification handler code here
CDatabase database;
CString sSql;
CString sCatID, sCategory;
CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString sDsn;
CString sFile = "c:\\works\\ReadDB\\Test.mdb"; // Change path here
int iRecord = 0;
// Create a pseudo DSN including the name of the Driver and the Excel file
// so we donhave to have an explicit DSN installed in our ODBC admin
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
TRY
{
// Open the database
database.Open(NULL,false ,false ,sDsn);
// the recordset
CRecordset recset( &database );
// Build the SQL query string
sSql = "SELECT CatID, Category "
"FROM Categories";
// Execute the query)
recset.Open(CRecordset::forwardOnly,sSql,CRecordset::readOnly);
ResetListControl();
// Column heading
m_ListControl.InsertColumn(1,"Cat ID",LVCFMT_LEFT,30,0);
m_ListControl.InsertColumn(1,"Category",LVCFMT_LEFT,30,1);
// Browse the result
while ( !recset.IsEOF() )
{
// Read one record
recset.GetFieldValue("CatID",sCatID);
recset.GetFieldValue("Category",sCategory);
// Insert values into the list control
m_ListControl.InsertItem(0,sCatID,0);
m_ListControl.SetItemText(0,1,sCategory);
// goto next record
recset.MoveNext();
}
// Close the database
database.Close();
}
CATCH(CDBException, e)
{
// If a database exception occured, pop up error msg
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}
void CReadDBDlg::ResetListControl()
{
m_ListControl.DeleteAllItems();
int iNbrOfColumns;
CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);
if (pHeader)
{
iNbrOfColumns = pHeader->GetItemCount();
}
for (int i = iNbrOfColumns; i >= 0; i--)
{
m_ListControl.DeleteColumn(i);
}
}
‘捌’ mybatis是如何将sql执行结果封装为目标对象并返回的都有哪些映射形式
是写一个resultmap然后指明字段和属性映射关系就行
‘玖’ 怎么把sql查询到的数据用java封装成对象放到list里
1.新建一个实体类,定义成员变量的分别用于封装你的数据。2.新建一个List集合用于存储实体类对象3.new一个对象,用JDBC读取sql语句,分别给实体类对象的成员变量赋值,再将对象add到集合中,完毕。
‘拾’ 求高手指教下。我最近在做项目,要求我把SQL封装成java的接口包
和数据库相关的都可以放你的接口里。
另外一些常用的数据操作的方法,也可以一并放进去。