数据库连接-以及如何在asp.net中调用它 [英] Database connection - And how to call it in asp.net

查看:50
本文介绍了数据库连接-以及如何在asp.net中调用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class clsCon:System.Web.UI.Page
    {
       
        public static SqlConnection conn_new = new SqlConnection();


        public static SqlConnection connect(string strConStr)
        {
            try
            {


                if (conn_new.State != System.Data.ConnectionState.Open)
                {
                    conn_new.ConnectionString = strConStr;
                    conn_new.Open();
                }
                else
                {
                    return null;
                }
               

            }

            catch
            {
               

            }
            return conn_new;
        }

        public static SqlDataReader ReadTable(string strReadStr)
        { 
              
                SqlCommand COMMA = new SqlCommand(strReadStr, conn_new);
                SqlDataReader rdNew;
                rdNew = COMMA.ExecuteReader();
                return rdNew;
                
                        
        }

        public static Boolean AddEditDel(string strAddEditDel)
        {
            SqlCommand ADDCOM = new SqlCommand(strAddEditDel, conn_new);
            int a;
            a = ADDCOM.ExecuteNonQuery();
            if (a == 0)
                return false;
            else
                return true;


        }
      

      

推荐答案

首先,此问题与ASP.NET无关.您尝试与数据库一起使用哪种类型的应用程序都没有关系.有没有听说过关注点分离?

看来您迷路了.您只需要从以下概述中了解ADO.NET的工作原理:
http://en.wikipedia.org/wiki/Ado.net [ http://msdn.microsoft.com/en-us/library/aa286484.aspx [ ^ ],
http://www.devlist.com/ConnectionStringsPage.aspx [为初学者使用ADO.NET [
First of all, this question has nothing to do with ASP.NET. It does not matter what type of application you are trying to use with the databases. Ever heard of separation of concerns?

It looks like you are lost pretty well. You just need to learn how ADO.NET works, from the overviews:
http://en.wikipedia.org/wiki/Ado.net[^],
http://msdn.microsoft.com/en-us/library/aa286484.aspx[^],
http://www.devlist.com/ConnectionStringsPage.aspx[^].

This CodeProject article will give you very short introduction with basic code samples:
Using ADO.NET for beginners[^].

—SA


这篇关于数据库连接-以及如何在asp.net中调用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆