本文介绍了如何发表全球声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SqlConnection con = new SqlConnection(@"DataSource=.\SQLEXPRESS;AttachDbFilename=E:\prashantcs\crm111\CRM111.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");

>我有上面显示的代码.我在每一页上都一遍又一遍地声明它
我之所以这样问,是因为我需要在不同的桌面上安装它,因此每次我更改所有页面的路径时,它都会使用该特定计算机的路径和name.ill进行更改,但只有在全局声明时才更改一次.

是否有任何全局声明它的方法.

请帮助我..

I have the code shown above.I am declaring it again and again for each and every page
The reason why i am asking this is i need to install it different desktops so every time i am changing the path for all the pages so that it takes that particular computers path and name.ill change it but only once if i declare it globally.

Is there any method for declaring it globally.

plz help me..

推荐答案


public class Db
{
	public Db()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public static SqlConnection GetConnection()
    {
        SqlConnection cn = new SqlConnection();
       // cn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["cnn"].ToString();
cn.ConnectionString=@"DataSource=.\SQLEXPRESS;AttachDbFilename=E:\prashantcs\crm111\CRM111.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
        cn.Open();
        return cn;
    }
}



将此方法用作



use this method as

SqlCommand cmd12111 = new SqlCommand();
           cmd12111.CommandText = "insert_File_Request1";
           cmd12111.CommandType = CommandType.StoredProcedure;
           cmd12111.Connection = Db.GetConnection();//Db class method
           cmd12111.Parameters.AddWithValue("ReqControlNo", ReqControlNo);
           cmd12111.Parameters.AddWithValue("ReqDate", ReqDate);
           cmd12111.Parameters.AddWithValue("ReqTime", ReqTime);
           cmd12111.ExecuteNonQuery();
           cmd12111.Connection.Close();



希望对您有帮助.



hope it will helps you.


这篇关于如何发表全球声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 17:24
查看更多