精华内容
下载资源
问答
  • SQL数据库连接

    2019-10-03 19:15:51
    using System; using System.Collections.Generic; using System.Linq;...using System.Text; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Web; using...
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
    using System.Web;
    using System.Web.Configuration;
    using System.Configuration;
    
    namespace DAL
    {
        public class cls_SQLFunction
        {
            string connectionString = "";
            System.Configuration.ConnectionStringSettings connString = System.Configuration.ConfigurationManager.ConnectionStrings["K3ConnectionString"];
    
            /// <summary>
            /// 读取数据库
            /// </summary>
            /// <param name="ComTxt">数据库查询语句</param>
            /// <param name="TableName">表名</param>
            /// <returns>查询结果——数据集</returns>
            public DataSet Read_DataSet(string ComTxt, string TableName)
            {
                try
                {
                    if (null != connString)
                    {
                        connectionString = connString.ConnectionString;
                    }
                    SqlConnection con;
                    SqlCommand selectcmd;
                    con = new SqlConnection(connectionString);
                    con.Open();
                    selectcmd = new SqlCommand();
                    selectcmd.CommandText = ComTxt;
                    selectcmd.CommandTimeout = 1800;
                    SqlDataAdapter adapter = new SqlDataAdapter(selectcmd.CommandText, con);
                    adapter.SelectCommand.CommandTimeout = 1800;
                    DataSet ds = new DataSet();
                    adapter.Fill(ds, TableName);
                    DataTable dt = ds.Tables[TableName];
                    con.Close();
                    return ds;
                }
                catch
                {
                    DataSet ds = new DataSet();
                    ds = null;
                    return ds;
                }
            }
    
            //--------------------------------------------------------------------------------
            /// <summary>
            /// 插入、删除、修改数据库
            /// </summary>
            /// <param name="ComTxt">SQL语句</param>
            public bool SQLUpdate(string ComTxt)
            {
                try
                {
                    if (null != connString)
                    {
                        connectionString = connString.ConnectionString;
                    }
                    SqlConnection con;
                    SqlCommand selectcmd;
                    con = new SqlConnection(connectionString);
                    con.Open();
                    selectcmd = new SqlCommand();
                    selectcmd.Connection = con;
                    selectcmd.CommandText = ComTxt;  //执行TSQL、表名、存储过程、一段SQL语句
                    selectcmd.ExecuteNonQuery();
                    con.Close();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
    
            //--------------------------------------------------------------------------------
            /// <summary>
            /// 数据库二进制数据写入
            /// </summary>
            /// <param name="ComTxt">SQL语句</param>
            /// <param name="File">文件二进制流</param>
            /// <returns>是否写入成功</returns>
            public bool SQLUpdate_Photo(string ComTxt, byte[] File)
            {
                try
                {
                    if (null != connString)
                    {
                        connectionString = connString.ConnectionString;
                    }
                    SqlConnection con;
                    SqlCommand selectcmd;
                    con = new SqlConnection(connectionString);
                    con.Open();
                    selectcmd = new SqlCommand(ComTxt, con);
                    selectcmd.Parameters.Add("@File", SqlDbType.Image);
                    selectcmd.Parameters[0].Value = File;
                    selectcmd.ExecuteNonQuery();
                    con.Close();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    }
    

      

    转载于:https://www.cnblogs.com/laojiefang/archive/2012/05/09/2491142.html

    展开全文
  • <p>I am trying to connect my C# application to sql server using php since my sever is Web Hosting. <p>I tried using Web Client Class <pre><code>private void BtnLogin_Click(object sender, EventArgs ...
  • 2、数据库: 3、代码: <%@page import="javax.swing.JSpinner"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> ...

    一、具备条件

    在这里插入图片描述

    二、数据库:

    在这里插入图片描述



    三、源代码:

    <%@page import="javax.swing.JSpinner"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>测试页面</title>
    </head>
    <body>
    <%
    		Connection con = null;
    		Statement st;
    		ResultSet rs;
    		try {
    			Class.forName("com.mysql.cj.jdbc.Driver");
    		}catch(Exception ex) {}
    		String uri = "jdbc:mysql://localhost:3306/wetalk?"+
    		"useSSL=false&serverTimezone=CST&characterEncoding=utf-8";
    		String user = "root";
    		String password = "";
    		try {
    			con = DriverManager.getConnection(uri,user,password);
    			out.print("连接成功");
    		}
    		catch(SQLException e){
    			System.out.println(e);
    		}
    		try {
    			st = con.createStatement();
    			rs = st.executeQuery("SELECT * FROM talks");
    			while(rs.next()){
    				out.print(rs.getString(2));	
    				out.print(rs.getString(3));	
    			}
    			con.close();
    		}
    		catch(SQLException e) {
    			System.out.println(e);
    		}
    
    %>
    
    </body>
    </html>
    
    
    


    四、调试:

    1、调试问题:

    在这里插入图片描述


    2、解决办法:
    加上:

    <%@page import="javax.swing.JSpinner"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*"%>
    
    展开全文
  • 需要用到这段代码,但原码是SQL数据连接,本人用的是ACC,请帮忙改下换成ACC数据连接方式。谢谢! Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls....
  • //连接服务器和数据库test String userName = "sa"; //默认用户名 String userPwd = "123456789"; //密码 Connection dbConn; try { Class.forName(driverName); dbConn = DriverManager....
  • <div class="post-text" itemprop="text"> <p>If you setup an Azure website to run PHP 5.5, the "sqlsrv" extension disappears, presumably because the current release of that extension ...
  • <link rel="stylesheet" type="text/css" href="css/animate-custom.css" /> <!-- Codrops top bar --> <div class="clr"></div> </div><!--/ Codrops top bar --> ...
  • 使用Eclipse做登陆界面,连接MySQL 8.0,测试过连接数据库应该是成功的,可能是struts配置有问题,新手不知道问题出在哪里,请帮忙看一下代码,我标注几个我可能出问题又不知道怎么改的地方 //login.jsp //此处...
  • 前面出了一个 Unity3D连接MYSQL数据库的教程,有网友问我关于Webplayer下载如何连接MYSQL数据库,这个出一个系列的教程 1,首先处理好虚拟主机下MYSQL数据库初始化 MYSQL管理器下 创建--数据库--表SQL 脚本 ...
    前面出了一个 Unity3D连接MYSQL数据库的教程,有网友问我关于Webplayer下载如何连接MYSQL数据库,这个出一个系列的教程
    

    1,首先处理好虚拟主机下MYSQL数据库初始化

    MYSQL管理器下 创建--数据库--表SQL

    脚本

    CREATE TABLE `getfh_15188775_linmdb`.`u_table` (
    `pname` TEXT NOT NULL ,
    `ppwd` TEXT NOT NULL 
    )
    

      

    分别插入3条数据

    INSERT INTO `getfh_15188775_linmdb`.`u_table` (
    `pname` ,
    `ppwd` 
    )
    VALUES (
    'admin', '123'
    );
    
    
    
    
    INSERT INTO `getfh_15188775_linmdb`.`u_table` (
    `pname` ,
    `ppwd` 
    )
    VALUES (
    'test88', 'linm'
    );
    
    
    
    INSERT INTO `getfh_15188775_linmdb`.`u_table` (
    `pname` ,
    `ppwd` 
    )
    VALUES (
    'unity', 'testunity3d'
    );
    

      

    2,写一个简单的PHP文件,上传到虚拟主机空间测试数据库连接

    请认真手打一遍,拒绝伸手党,否则后面PHP代码有困难,上图

     

    代码很简单,需要一定的PHP基础知识,自己百度一下就会了,不会百度,,,,自己面壁去

    测试虚拟主机运行地址,,, xxx/uphp.php  【xxx为你的虚拟主机网络地址】

     如下图,则说明读取数据库中的数据成功

    服务器这边基本已经配置好了,未完待续......

     

    展开全文
  • c# SQLServer 数据库连接 using System;using System.Data;using System.Configuration;using System.Web;using System.Data.SqlClient;using System.Text;using System.Collections;namespace BaseProject.Data{ ...
    c# SQLServer 数据库连接

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Data.SqlClient;
    using System.Text;
    using System.Collections;
    namespace BaseProject.Data
    {

        public class DbAccess
        {
            private string _EditString = "if exists({0}) begin {1} end else begin {2} end";
            public string EditString
            {
                set { this._EditString = value; }
                get { return this._EditString; }
            }
            SqlConnection conn = null;
            SqlCommand cmd = null;
            public DbAccess()
            {
                //
                // TODO: 在此处添加构造函数逻辑
                //
                conn = new SqlConnection();
                conn.ConnectionString = Convert.ToString(ConfigurationManager.AppSettings["datasource"]); //Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["datasource"]);
                //conn.ConnectionString = "initial catalog=idyan_new;data source=.;user id=bt;password=btbtbtbt;Connect Timeout=5000";
                cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandTimeout = 0;

            }
            public DbAccess(string constr)
            {

                //
                // TODO: 在此处添加构造函数逻辑
                //
                conn = new SqlConnection();
                //conn.ConnectionString = "initial catalog=pubs;data source=.;user id=sa;password=";
                //conn.ConnectionString = Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["datasource"]);
                conn.ConnectionString = constr;// "initial catalog=idyan_new;data source=.;user id=bt;password=btbtbtbt";
                cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandTimeout = 0;

            }
            /// <summary>
            /// 获取数据根据sql语句
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public DataTable GetTable(string sql)
            {
                DataSet ds = new DataSet();

                try
                {
                    cmd.CommandText = sql;
                    cmd.CommandType = CommandType.Text;
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;

                    da.Fill(ds);
                }
                catch (Exception ex)
                {


                    return null;

                }
                return ds.Tables[0] ?? new DataTable();
            }
            /// <summary>
            /// 获取数据根据sql语句
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public DataSet GetDataSet(string sql)
            {
                DataSet ds = new DataSet();

                try
                {
                    cmd.CommandText = sql;
                    cmd.CommandType = CommandType.Text;
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;

                    da.Fill(ds);
                }
                catch (Exception ex)
                {


                    return null;

                }
                return ds;
            }
            /// <summary>
            /// 获取数据根据sql语句
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public DataSet GetDataSet(string sql, SqlParameter[] pas)
            {
                DataSet ds = new DataSet();

                try
                {
                    cmd.Parameters.Clear();
                    cmd.CommandText = sql;
                    foreach (SqlParameter pa in pas)
                    {
                        cmd.Parameters.Add(pa);
                    }
                    cmd.CommandType = CommandType.Text;
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;

                    da.Fill(ds);
                }
                catch (Exception ex)
                {


                    return null;

                }
                return ds;
            }
            /// <summary>
            /// 获取数据根据sql语句 带参数 的
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="pas"></param>
            /// <returns></returns>
            public DataTable GetTable(string sql, params SqlParameter[] pas)
            {
                DataSet ds = new DataSet();
                try
                {
                    cmd.CommandText = sql;
                    cmd.CommandType = CommandType.Text;
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;
                    cmd.Parameters.Clear();

                    foreach (SqlParameter temppa in pas)
                    {
                        cmd.Parameters.Add(temppa);
                    }


                    da.Fill(ds);
                }
                catch (Exception ex)
                {


                    return null;
                }
                return ds.Tables[0] ?? new DataTable();
            }
            /// <summary>
            /// 获取数据根据sql语句 带参数 的
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="pas"></param>
            /// <returns></returns>
            public DataTable GetProcTable(string procname, params SqlParameter[] pas)
            {
                DataSet ds = new DataSet();
                try
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = procname;
                    //cmd.CommandText = sql;
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;
                    cmd.Parameters.Clear();

                    foreach (SqlParameter temppa in pas)
                    {
                        cmd.Parameters.Add(temppa);
                    }

     

                    da.Fill(ds);
                }
                catch (Exception ex)
                {


                    return null;
                }
                return ds.Tables[0] ?? new DataTable();
            }
            /// <summary>
            /// 获取数据根据sql语句 带参数 的
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="pas"></param>
            /// <returns></returns>
            public DataTable GetProcCursorTable(string procname, params SqlParameter[] pas)
            {
                DataSet ds = new DataSet();
                try
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = procname;
                    //cmd.CommandText = sql;
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;
                    cmd.Parameters.Clear();

                    foreach (SqlParameter temppa in pas)
                    {
                        cmd.Parameters.Add(temppa);
                    }

     

                    da.Fill(ds);
                }
                catch (Exception ex)
                {


                    return null;
                }
                return ds.Tables[1] ?? new DataTable();
            }
            /// <summary>
            /// 获取数据根据sql语句 带参数 的
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="pas"></param>
            /// <returns></returns>
            public int GetProcState(string procname, params SqlParameter[] pas)
            {
                int state = 0;
                try
                {
                    OpenConn();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = procname;
                    cmd.Parameters.Clear();
                    foreach (SqlParameter temppa in pas)
                    {
                        cmd.Parameters.Add(temppa);
                    }
                    cmd.ExecuteNonQuery();
                    CloseConn();
                    state = Convert.ToInt32(pas[pas.Length - 1].Value);

                }
                catch
                {
                    return 0;
                }
                return state;
            }
            /// <summary>
            /// 获取数据根据sql语句 带参数 的
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="pas"></param>
            /// <returns></returns>
            public int GetProcStateNo(string procname, params SqlParameter[] pas)
            {
                int state = 0;
                try
                {
                    OpenConn();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = procname;
                    cmd.Parameters.Clear();
                    foreach (SqlParameter temppa in pas)
                    {
                        cmd.Parameters.Add(temppa);
                    }
                    cmd.ExecuteNonQuery();
                    CloseConn();
                    state = 1;

                    // state = Convert.ToInt32(pas[pas.Length - 1].Value);

                }
                catch
                {

                    return 0;
                }
                return state;
            }
            /// <summary>
            /// 存储过程返回值的
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="pas"></param>
            /// <returns></returns>
            public string GetProcStateReturnValue(string procname, params SqlParameter[] pas)
            {
                string state = "";
                try
                {
                    OpenConn();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = procname;
                    cmd.Parameters.Clear();
                    foreach (SqlParameter temppa in pas)
                    {
                        cmd.Parameters.Add(temppa);
                    }
                    cmd.Parameters.AddWithValue("@Return_Value", "").Direction = ParameterDirection.ReturnValue;
                    cmd.ExecuteNonQuery();
                    state = Convert.ToString(cmd.Parameters["@Return_Value"].Value);
                    state = state == null ? ("") : (state);
                    CloseConn();


                    // state = Convert.ToInt32(pas[pas.Length - 1].Value);

                }
                catch
                {

                    return "";
                }
                return state;
            }
            /// <summary>
            /// 根据sql语句返回跟新状态
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public bool GetState(string sql)
            {
                bool succ = false;
                try
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    OpenConn();
                    succ = cmd.ExecuteNonQuery() > 0 ? (true) : (false);
                    CloseConn();
                }
                catch (Exception ex)
                {


                    return false;
                }
                return succ;

            }
            /// <summary>
            /// 根据sql语句返回跟新状态带参数的
            /// </summary>
            /// <param name="sql">sql语句</param>
            /// <param name="pas">参数的集合</param>
            /// <returns></returns>
            public bool GetState(string sql, params SqlParameter[] pas)
            {
                bool succ = false;
                try
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    cmd.Parameters.Clear();

                    foreach (SqlParameter temppa in pas)
                    {
                        cmd.Parameters.Add(temppa);
                    }
                    OpenConn();
                    succ = cmd.ExecuteNonQuery() > 0 ? (true) : (false);
                    CloseConn();
                }
                catch
                {

                    // this.ShowError(ex.Message);
                    //using (System.IO.StreamWriter sw = new System.IO.StreamWriter("D:\\error2008.txt"))
                    //{
                    //    sw.Write(ex.Message);
                    //    sw.Flush();
                    //}
                    return false;
                }
                return succ;

            }
            /// <summary>
            /// 根据sql语句返回第一个单元格的数据
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public string GetOne(string sql)
            {
                string res = "";
                try
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    OpenConn();
                    res = cmd.ExecuteScalar() == null ? ("") : (Convert.ToString(cmd.ExecuteScalar()));
                    CloseConn();
                }
                catch (Exception ex)
                {


                    return null;
                }
                return res;
            }
            /// <summary>
            ///  根据sql语句返回第一个单元格的数据带参数的
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="pas"></param>
            /// <returns></returns>
            public string GetOne(string sql, params SqlParameter[] pas)
            {
                string res = "";
                try
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    cmd.Parameters.Clear();

                    foreach (SqlParameter temppa in pas)
                    {
                        cmd.Parameters.Add(temppa);
                    }
                    OpenConn();
                    res = cmd.ExecuteScalar() == null ? ("") : (Convert.ToString(cmd.ExecuteScalar()));
                    CloseConn();
                }
                catch (Exception ex)
                {
                    CloseConn();

                    return null;
                }
                return res;
            }
            /// <summary>
            /// 返回数据的DataReader
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public SqlDataReader GetDataReader(string sql)
            {
                SqlDataReader dr = null;
                try
                {
                    cmd.CommandType = CommandType.Text;
                    conn.Open();
                    cmd.CommandText = sql;
                    dr = cmd.ExecuteReader();
                }
                catch (Exception ex)
                {


                    return null;
                }
                return dr;
            }
            /// <summary>
            /// 返回数据的DataReader带参数的
            /// </summary>
            /// <param name="sql"></param>
            /// <param name="pas"></param>
            /// <returns></returns>
            public SqlDataReader GetDataReader(string sql, params SqlParameter[] pas)
            {
                SqlDataReader dr = null;
                try
                {
                    cmd.CommandType = CommandType.Text;
                    conn.Open();
                    cmd.Parameters.Clear();

                    foreach (SqlParameter temppa in pas)
                    {
                        cmd.Parameters.Add(temppa);
                    }

                    cmd.CommandText = sql;
                    dr = cmd.ExecuteReader();
                }
                catch (Exception ex)
                {


                    return null;
                }
                return dr;
            }
            /// <summary>
            /// 事务处理函数
            /// </summary>
            /// <param name="al"></param>
            /// <returns></returns>
            public bool GetTranState(ArrayList al)
            {
                cmd.CommandType = CommandType.Text;
                OpenConn();
                SqlTransaction tran = conn.BeginTransaction();
                cmd.Transaction = tran;
                try
                {
                    for (int i = 0; i < al.Count; i++)
                    {
                        cmd.CommandText = Convert.ToString(al[i]);
                        cmd.ExecuteNonQuery();
                    }

                    tran.Commit();
                    CloseConn();
                }
                catch
                {

                    tran.Rollback();
                    CloseConn();
                    return false;
                }
                return true;

            }
            /// <summary>
            /// 事务处理函数
            /// </summary>
            /// <param name="al"></param>
            /// <returns></returns>
            public bool GetTranStateParameter(ArrayList al)
            {
                cmd.CommandType = CommandType.Text;
                OpenConn();
                SqlTransaction tran = conn.BeginTransaction();
                cmd.Transaction = tran;
                try
                {
                    for (int i = 0; i < al.Count; i++)
                    {
                        SqlTranModel stm = (SqlTranModel)al[i];
                        cmd.CommandText = Convert.ToString(stm.Sql);
                        SqlParameter[] pas = stm.Pas;
                        cmd.Parameters.Clear();
                        foreach (SqlParameter temp in pas)
                        {
                            cmd.Parameters.Add(temp);
                        }
                        cmd.ExecuteNonQuery();
                    }

                    tran.Commit();
                    CloseConn();
                }
                catch
                {

                    tran.Rollback();
                    CloseConn();
                    return false;
                }
                return true;

            }
            /// <summary>
            /// 分页函数
            /// </summary>
            /// <param name="pagesize"></param>
            /// <param name="columns"></param>
            /// <param name="tablename"></param>
            /// <param name="pid"></param>
            /// <param name="order"></param>
            /// <param name="current"></param>
            /// <returns></returns>
            public DataTable GetPageData(int current, int pagesize, string columns, string tablename, string pid, string where, string order)
            {
                current = current - 1 >= 0 ? (current - 1) : (0);
                string sql = string.Format("select top {0} {1} from {2} where 1=1 and {3} not in(select top {4}{3} from {2} where 1=1{5}  order by {6}){5} order by {6}", pagesize, columns, tablename, pid, current * pagesize, where, order);
                return GetTable(sql);
            }
            /// <summary>
            /// 分页存储过程的调用
            /// </summary>
            /// <param name="current"></param>
            /// <param name="pagesize"></param>
            /// <param name="columns"></param>
            /// <param name="tablename"></param>
            /// <param name="pid"></param>
            /// <param name="where"></param>
            /// <param name="order"></param>
            /// <returns></returns>
            public DataTable GetProcPageData(int current, int pagesize, string columns, string tablename, string pid, string where, string order, string ordertype)
            {
                SqlParameter[] pas = { new SqlParameter("@PageIndex", current), new SqlParameter("@PageSize", pagesize), new SqlParameter("@Columns", columns), new SqlParameter("@Tablename", tablename), new SqlParameter("@Where", where), new SqlParameter("@Order", order), new SqlParameter("@OrderType", ordertype), new SqlParameter("@Pid", pid) };
                return GetProcTable("Pages", pas);
                //current = current - 1 >= 0 ? (current - 1) : (0);
                //string sql = string.Format("select top {0} {1} from {2} where 1=1 and {3} not in(select top {4}{3} from {2} where 1=1{5}  order by {6}){5} order by {6}", pagesize, columns, tablename, pid, current * pagesize, where, order);
                //return GetTable(sql);
            }
            /// <summary>
            /// 分页存储过程的调用
            /// </summary>
            /// <param name="current"></param>
            /// <param name="pagesize"></param>
            /// <param name="columns"></param>
            /// <param name="tablename"></param>
            /// <param name="pid"></param>
            /// <param name="where"></param>
            /// <param name="order"></param>
            /// <returns></returns>
            public DataTable GetProcData(int current, int pagesize, string columns, string tablename, string pid, string where, string order, string resultCount, string distinct)
            {
                SqlParameter[] pas = { new SqlParameter("@TableNames", SqlDbType.NVarChar, 200), new SqlParameter("@PrimaryKey", SqlDbType.NVarChar, 100), new SqlParameter("@Order", SqlDbType.NVarChar, 200), new SqlParameter("@CurrentPage", SqlDbType.Int), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@Fields", SqlDbType.NVarChar, 800), new SqlParameter("@Filter", SqlDbType.NVarChar, 1000), new SqlParameter("@ResultCount", SqlDbType.NVarChar, 12), new SqlParameter("@distinct", SqlDbType.NVarChar, 12) };
                pas[0].Value = tablename;
                pas[1].Value = pid;
                pas[2].Value = order;
                pas[3].Value = current;
                pas[4].Value = pagesize;
                pas[5].Value = columns;
                pas[6].Value = where;
                pas[7].Value = resultCount;
                pas[8].Value = distinct;
                return this.GetProcTable("Pages", pas);
                //SqlParameter[] parameters = {
                //                                new SqlParameter("@TableNames",SqlDbType.VarChar,8000),
                //                                new SqlParameter("@PrimaryKey", SqlDbType.VarChar,8000),
                //                                new SqlParameter("@Order", SqlDbType.VarChar,8000),
                //                                new SqlParameter("@CurrentPage",SqlDbType.Int),
                //                                new SqlParameter("@PageSize", SqlDbType.Int),
                //                                new SqlParameter("@Fields",SqlDbType.VarChar,8000),
                //                                new SqlParameter("@Filter", SqlDbType.VarChar,8000),
                //                                new SqlParameter("@Group", SqlDbType.VarChar,8000)
                //                            };
                //parameters[0].Value = tablename;
                //parameters[1].Value = pid;
                //parameters[2].Value = order;
                //parameters[3].Value = current;
                //parameters[4].Value = pagesize;
                //parameters[5].Value = columns;
                //parameters[6].Value = where;
                //parameters[7].Value = "";
                //DataSet ds = DbHelperSQL.RunProcedure("Pages", parameters, "data");

                //return ds.Tables["data"];//
                //return GetProcTable("Pages", pas);
                //current = current - 1 >= 0 ? (current - 1) : (0);
                //string sql = string.Format("select top {0} {1} from {2} where 1=1 and {3} not in(select top {4}{3} from {2} where 1=1{5}  order by {6}){5} order by {6}", pagesize, columns, tablename, pid, current * pagesize, where, order);
                //return GetTable(sql);
            }
            /// <summary>
            /// 分页存储过程的调用
            /// </summary>
            /// <param name="current"></param>
            /// <param name="pagesize"></param>
            /// <param name="columns"></param>
            /// <param name="tablename"></param>
            /// <param name="pid"></param>
            /// <param name="where"></param>
            /// <param name="order"></param>
            /// <returns></returns>
            public DataTable GetProcAdminData(int current, int pagesize, string columns, string tablename, string pid, string where, string order, string resultCount, string distinct)
            {
                SqlParameter[] pas = { new SqlParameter("@TableNames", SqlDbType.NVarChar, 200), new SqlParameter("@PrimaryKey", SqlDbType.NVarChar, 100), new SqlParameter("@Order", SqlDbType.NVarChar, 200), new SqlParameter("@CurrentPage", SqlDbType.Int), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@Fields", SqlDbType.NVarChar, 800), new SqlParameter("@Filter", SqlDbType.NVarChar, 200), new SqlParameter("@ResultCount", SqlDbType.NVarChar, 24), new SqlParameter("@Distinct", SqlDbType.NVarChar, 12) };
                pas[0].Value = tablename;
                pas[1].Value = pid;
                pas[2].Value = order;
                pas[3].Value = current;
                pas[4].Value = pagesize;
                pas[5].Value = columns;
                pas[6].Value = where;
                pas[7].Value = resultCount;
                pas[8].Value = distinct;
                return this.GetProcTable("Pages", pas);

            }
            /// <summary>
            /// 打开连接
            /// </summary>
            public void OpenConn()
            {
                if (conn.State != ConnectionState.Open)
                {
                    try
                    {
                        conn.Open();
                    }
                    catch (Exception ex)
                    {


                        return;
                    }
                }
            }
            /// <summary>
            /// 关闭连接
            /// </summary>
            public void CloseConn()
            {
                if (conn.State != ConnectionState.Closed)
                {
                    try
                    {
                        conn.Close();

                    }
                    catch (Exception ex)
                    {


                        return;
                    }
                }
            }
            public void DisposeConn()
            {
                try
                {
                    if (conn.State != ConnectionState.Closed)
                    {
                        try
                        {
                            conn.Close();

                        }
                        catch (Exception ex)
                        {


                            return;
                        }
                    }
                }
                catch
                {

                }
            }

     

        }
        public class SqlTranModel
        {
            private string _sql;
            public string Sql
            {
                set { this._sql = value; }
                get { return this._sql; }
            }
            private SqlParameter[] _pas;
            public SqlParameter[] Pas
            {
                set { this._pas = value; }
                get { return this._pas; }
            }
        }
    }

    类 谢谢大家的支持,帮我点下需要的广告谢谢我会更加努力整理我的百科服务大家

    转载于:https://www.cnblogs.com/bestsaler/archive/2009/04/02/1835708.html

    展开全文
  • out.print("数据库驱动程序装入错误"); } try{ String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+request.getRealPath("/")+"db_database.mdb"; Connection conn=DriverManager.get...
  • 代码都已经打完了,但是一直连接不成功,sqlserver数据库驱动也下下来了并放到buding path里了,sqlserver协议tcp/ip也更改了,数据库也用用户名密码登陆了,还差什么啊,求大神指教,下面是代码,都是网上的,应该...
  • webserve_数据库操作

    2016-05-18 23:43:16
    JDBC进行数据库连接操作 在page指令中可以使用import导入所需要的java开发包java.sql,进行数据库开发。 查询代码如下所示<%@page contentType="text/html" pageEncoding="GBK" %> <%@page import="java.sql.*" %> ...
  • <%@pagelanguage="java"contentType="text/html;charset=gb2312" pageEncoding="gb2312"%> <%@pageimport="java.sql.*"%> <!DOCTYPEht...
  • 本人初学web组件,很多基础不会,望各位大神不要鄙视~~~~ -----login.java---- package com.tsinghua; import javax.servlet.http.*; import java.io.*; public class Login extends HttpServlet{ ...
  • <div class="post-text" itemprop="text"> <p>I already used some solutions put forward in other threads but it just doesn't want to work. My MYSQL version is: 5.5.38 and here is the code I use (the ...
  • <div class="post-text" itemprop="text"> <p>In my web app I have 2 different connections the main connection and the dynamic database.I used the main connection to create new database with tables ...
  • <div class="post-text" itemprop="text"> <p>I am trying to connect hosted webs application to Local database. First I was getting <code>Fatal error: Call to undefined function odbc_connect()</code> ...
  • cmd.Parameters.Add(new SqlParameter("学号", txtNo.Text)); using (SqlDataAdapter adapter = new SqlDataAdapter(cmd)) { if (con.State != ConnectionState.Open) con.Open(); adapter.Fill(dt); } ...
  •  if (txtUserName.Text.Trim() == "" || txtUserPass.Text.Trim() == "")  {  Response.Write("<script>alert('登录名和密码不能为空!');location='javascript:history.go(-1)';</script>");...
  • <p>I have a simple web form, which I want the user to fill out and when they click the submit button the information from the form should be inserted into the correct tables in the mySQL database for ...
  • 小弟想用jsp文件输入数据到mysql数据库中 这是代码 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> *,java.sql.Connection, java.sql.DriverManager,java.sql....
  • Message org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.WebRoot._001_jsp Description The server encountered an unexpected condition that prevented it from ...
  • <code class="language-java">package java_zhuyoukai.web.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; ...
  • 1、ASP.NET连接数据库 配置文件中的代码: ;database=db_Vote;integrated security=SSPI"/> 2、但运行时出现下面的错误 找不到网络路径。 说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪...
  • 在app.config文件中写上数据库连接信息: app.config文件中代码解析: 小注: 同理web程序,可以把数据库连接信息放到web.config中。C#.NET万能数据库访问封装类代码如下:(该代码来自百度文库,非自己编写)...
  • **C#使用ajax连接SQL Server数据库的时候有错误** **HTML页面** ``` 查询学生 <input type="text" id="checkInput" placeholder="请输入要查询学生的姓名关键词:" style="width:200px;height:50px" /> ...
  • str_sql = str_sql + " WHERE DEVICE_NAME LIKE '" + TxtDevice.Text + "%'"; } Oracle.ManagedDataAccess.Client.OracleDataAdapter da = new Oracle.ManagedDataAccess.Client.OracleDataAdapter(str_sql, conn...
  • //获得connecttion对象,该对象代表一个数据库连接 dbconn = DriverManager.getConnection(dburl,username,password); }catch(ClassNotFoundException e1) { System.out.println(e1); ...

空空如也

空空如也

1 2 3 4 5 ... 9
收藏数 180
精华内容 72
关键字:

web连接sql数据库text