如何发表全球声明 [英] how to make global declarations

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

问题描述

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..

推荐答案

如果所有台式机或PC都在网络中,则可以在其中一台PC中创建网络驱动器,并在其中复制mdf文件.共享驱动器.这样所有系统都可以从该网络路径访问文件.

有关Netwrok驱动器的更多信息,请参见此处..

http://support.microsoft.com/kb/308582 [ http://compnetworking.about.com/od/windowsxpnetworking/ht/mapnetworkdrive.htm [ ^ ]

并在您的连接字符串中指定该网络路径.

希望它能起作用.
if all the desktops or PCs are in Network then you can create a network drive in one of the PCs and copy the mdf file in that shared drive. so that all the systems can access the file from that network path.

see here for more on netwrok drives..

http://support.microsoft.com/kb/308582[^]

http://compnetworking.about.com/od/windowsxpnetworking/ht/mapnetworkdrive.htm[^]

and specify that network path in your connection string.

hope it works..


您可以添加一个类并使用诸如
的方法
you can add a class and make method like
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.


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

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