[英]what is the best way to create connection Class in C#
I have windows form that asking user name, password and databaseName, and the way I am using to connect database open to SQL injection!. 我有Windows窗体,询问用户名,密码和databaseName,以及我用来将数据库连接到SQL注入的方式! I want to create different class for my connection string, also want to use get and set methods if it is necessary.
我想为我的连接字符串创建不同的类,如果需要,还想使用get和set方法。 what is the best way to do that?
最好的方法是什么?
Thanks? 谢谢?
my Connection String 我的连接字符串
string db1 = "Data Source=" + txtDatabase.Text + ";User Id=" + txtUserID.Text.ToUpper() + ";Password=" + txtUserPassword.Text + ";";
connection builder 连接生成器
System.Data.SqlClient.SqlConnectionStringBuilder builder =
new System.Data.SqlClient.SqlConnectionStringBuilder();
builder["Data Source"] = "(local)";
builder["integrated Security"] = true;
builder["Initial Catalog"] = "AdventureWorks;NewValue=Bad";
Console.WriteLine(builder.ConnectionString);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.