本文介绍了我怎么知道这是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#中有关于医院系统的内容,其中包含超过50个子项目

即时创建类名DBAccess就像这样:

i have aproject in c# about hospital system wich contains more than 50 childforms
im create class name"DBAccess" like thise:

namespace emamTree
{
    public  class  DBAccess
    {
        public static string connectionString = ConfigurationManager.ConnectionStrings["TreeFinal"].ConnectionString ;

       public SqlCommand Intialize(string query, params SqlParameter[] prmArray)
        {
                SqlConnection cn = new SqlConnection(connectionString);

                SqlCommand cmd = new SqlCommand(query, cn);

                if (!query.Contains(" "))
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                if (prmArray.Length > 0)
                    cmd.Parameters.AddRange(prmArray);

                cn.Open();

                return cmd;
        }

        public  int ExcuteNonQuery(string query, params SqlParameter[] prmArray)
        {
            try
            {
                SqlCommand cmd = Intialize(query, prmArray);

                int affectedRows = cmd.ExecuteNonQuery();

                cmd.Connection.Close();

                return affectedRows;
            }
            catch (SqlException ex)
            {
                return ex.Number;
            }
        }

        public object ExcuteScalar(string query, params SqlParameter[] prmArray)
        {
            try
            {
                SqlCommand cmd = Intialize(query, prmArray);

                object value = cmd.ExecuteScalar();

                cmd.Connection.Close();

                return value;
            }
            catch (SqlException ex)
            {
                return ex.Number;
            }
        }

        public  SqlDataReader ExcuteReader(string query, params SqlParameter[] prmArray)
        {
                SqlCommand cmd = Intialize(query, prmArray);

                SqlDataReader sqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                return sqlDataReader;
        }

        public  DataTable ExcuteDataTable(string query, params SqlParameter[] prmArray)
        {
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(query, connectionString);

                if (!query.Contains(" "))
                    sqlDataAdapter.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;

                if (prmArray.Length > 0)
                    sqlDataAdapter.SelectCommand.Parameters.AddRange(prmArray);

                DataTable dt = new DataTable();
                sqlDataAdapter.Fill(dt);

                return dt;
        }

        public  DataSet ExcuteDataSet(string query, params SqlParameter[] prmArray)
        {
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(query, connectionString);

            if (!query.Contains(" "))
                sqlDataAdapter.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;

            if (prmArray.Length > 0)
                sqlDataAdapter.SelectCommand.Parameters.AddRange(prmArray);

            DataSet ds = new DataSet();
            sqlDataAdapter.Fill(ds);

            return ds;
        }
   }
}
each child form have save method:

public void Save()
{

     DBAccess db = new DBAccess();
     db.ExcuteNonQuery("insert into Patients  (FileNum,PatientTypeID,EngName,NationalityID,RelegionID) values  (@FileNum,@PatientTypeID,@EngName,,@NationalityID,@RelegionID)",
         new SqlParameter("@FileNum", txtFileNum.Text),
         new SqlParameter("@PatientTypeID", txtPatientTypeID.Text),
         new SqlParameter("@EngName", txtEngName.Text),
         new SqlParameter("@NationalityID", txtNationalityID.Text),
         new SqlParameter("@RelegionID", txtRelegionID.Text)
                         );

}



问题:

将数据库附加到SQL Server后,此代码是否正确且超过10用户同时工作?

先谢谢


Question:
Is this code correct or not after attach database into SQL server and more than 10 users works at the same time?
Thanks in Advance

推荐答案


这篇关于我怎么知道这是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 12:21