存储数据库详细信息并将其调用为Vb表单? [英] Store database details and call them to Vb form?

查看:65
本文介绍了存储数据库详细信息并将其调用为Vb表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mysql数据库进行开发。



我总是在每个表单的顶部声明我使用的数据库的详细信息。我的意思是,数据库名称,用户名,密码以及它的一切。我们知道,当我将应用程序部署到其他计算机时,这将不会很好。我想知道保存这些凭据的最佳方法,并允许某人在安装应用程序后设置它们(就像使用其他应用程序一样)。可以将它们保存为文本(.txt)文件吗?



如何将详细信息/变量保存到文本文件中?

我如何读/调用这些变量,以我的形式

解决方案
将它们保存到一个配置文件:

1)打开你的项目属性在解决方案资源管理器中,双击Settings.settings

2)在结果网格中,将Name更改为ConnectionString,并将Value设置为空白。将类型和范围分别保留为字符串和用户。

3)保存并关闭设置窗口。

4)阅读设置:

 Dim s as string = Properties.Settings.Default.ConnectionString 

5)写下你的设置:

 Properties.Settings.Default.ConnectionString =我的新设置值 
Properties.Settings.Default.Save()

在连接的详细信息将被保存在是好的,方便的XML文件必要时可编辑的外部程序。


I''m developing with mysql database.

I always declared the details about the database I use at the top of every form. I mean, the database name,username,password and everything about it. We know this will not be great when I deploy my app to other computers. I would like to know the best way to save these credentials and allow someone to set them after installling the app (like how it is done with other apps). May be saving them to a text (.txt) file?

How do I save the details/variables to a text file?
How do I read/call these variables to my forms?

解决方案

Save them to a config file:
1) Open your projects Properties in the solution explorer, and double click on "Settings.settings"
2) In the resulting grid, change the Name to "ConnectionString", and set the Value to blank. Leave Type and Scope as "string" and "User" respectively.
3) Save and close the settings window.
4) To read your setting:

Dim s as string = Properties.Settings.Default.ConnectionString

5) To write your setting:

Properties.Settings.Default.ConnectionString = "My new setting value"
Properties.Settings.Default.Save()

The connection details will be saved in an XML file that is nice and easy for external programs to edit if necessary.


这篇关于存储数据库详细信息并将其调用为Vb表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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