Imports MySqlDataMySqlClient
Public Shared Function getMySQL(ByVal sqlstr As String) As DataTable
Dim Conn As MySqlConnection = New MySqlConnection(mysql1)
Try
ConnOpen()
Dim da As New MySqlDataAdapter(sqlstr, Conn)
Dim ds As New DataSet
daFill(ds, "dt1")
ConnClose()
ConnDispose()
Return dsTables("dt1")
Catch ex As Exception
ConnClose()
ConnDispose()
Return Nothing
End Try
End Function
using System;
using SystemCollectionsGeneric;
using SystemText;
using SystemDataSqlClient;
using SystemData;
using SystemConfiguration;
using funddbconninterfaces;
namespace funddbconndbconn
{
public class SQLDBCommon
{
private readonly string constr = ConfigurationSettingsAppSettings["connstring"];//得到数据库联接(判断是什么联接)
int IDBCommonExecuteSQL(string sql)
{
int result = -1;
using (SqlConnection conn = new SqlConnection(constr))
{
SqlCommand cmd = new SqlCommand(sql, conn);
connOpen();
result= cmdExecuteNonQuery();
connClose();
}
return result;
}
/// <summary>
/// 查询 *** 作
/// </summary>
/// <param name="sql"></param>
/// <param name="tableName"></param>
/// <returns></returns>
SystemDataDataSet IDBCommonQuerySQL(string sql,string tableName)
{
DataSet ds = null;
SqlDataAdapter dsa =null;
SqlConnection conn=null;
try
{
{
conn = new SqlConnection(constr);
dsa = new SqlDataAdapter(sql,conn);
ds = new DataSet();
connOpen();
dsaFill(ds, tableName);
connClose();
}
}
catch (Exception ex)
{
throw new Exception(exMessage);
}
finally
{
if(conn!=null)
{
connClose();
}
}
return ds;
}
SystemDataIDataReader IDBCommonExecuteReader(string sql)
{
IDataReader dr = null;
return dr;
}
#region IDBCommon 成员
int IDBCommonExecuteSQL(string sql, params IDbDataParameter[] parameters)
{
int result = -1;
if (parameters != null)
{
using (SqlConnection conn = new SqlConnection(constr))
{
SqlCommand cmd = new SqlCommand(sql, conn);
foreach (IDbDataParameter para in parameters)
{
cmdParametersAdd(para);
}
connOpen();
result = cmdExecuteNonQuery();
connClose();
}
}
else
{
using (SqlConnection conn = new SqlConnection(constr))
{
SqlCommand cmd = new SqlCommand(sql, conn);
connOpen();
result = cmdExecuteNonQuery();
connClose();
}
}
return result;
}
#endregion
#region IDBCommon 成员
int IDBCommonOpenConn(string strconn,IDbConnection conn)
{
int falge = -1;
try
{
if (conn != null)
{
if (connState == ConnectionStateOpen)
{
connClose();
}
}
conn = new SqlConnection(strconn);
connOpen();//打开连接
falge = 1;
}
catch (Exception ex)
{
falge = -1;
throw new Exception("_数据库连接失败_:" + exMessage);//抛出错误信息
}
return falge;
}
}
#endregion
}
CoInitialize(NULL);//注册激活
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString="Provider=SQLOLEDB1;Persist Security Info=False;User ID=/这里改成登陆账号/;Initial Catalog=/这里改成数据库的名字/";//在这设置数据库
pConn->Open("", "", "/这里改成登陆密码/", adConnectUnspecified);
新建一个工程名叫mysql。从工具箱向form1窗体上拖一个按钮datagridview控件,按钮是触发连接数据库获取数据集,按钮的名称为显示datagridview控件是用于显示数据集内容。
以上就是关于vs2010已经连接了mysql数据库,接下来怎样对数据库进行 *** 作,比如查询,求一段代码。。。举例全部的内容,包括:vs2010已经连接了mysql数据库,接下来怎样对数据库进行 *** 作,比如查询,求一段代码。。。举例、求:C#--VS2005-SQL2005完整的对数据库的 *** 作程序代码、我用VS2010的C++写个程序要连接并读取SQLserver数据库中的数据求具体的实现代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)