如何使用C#从连接字符串中过滤数据库名称 [英] how can filter database name from connection string using c#
本文介绍了如何使用C#从连接字符串中过滤数据库名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有
我知道这是一个愚蠢的问题,但我不知道,所以请大家都需要帮助
尝试
{
使用(MySqlConnection con = 新 MySqlConnection(txtOtherConStr.Text.Trim()))
{
foreach ()
{
}
}
}
这是我的代码,我在txtOtherConStr.Text(数据源=本地主机; uid = root; pwd = root; database = Hr;)中的连接字符串
我想获得数据库=如何获得帮助meeeeeee
解决方案
我不是Regex专家,但是我猜想这种模式是一个不错的开始:database=(.*?)
.然后,您可以使用Match.Groups
属性获取数据库名称.
首先获取txtOtherConStr.Text in 一个字符串,例如 string st = txtOtherConStr.Text.Trim() 然后用(;)分割 字符串 [] st1 = st.split(;),然后您有了st1 [ 0 ],st1 [ 1 ],t1 [ 2 ],st1 [ 3 现在找到具有数据库的字符串. 我认为st1 [ 3 ]现在又通过(=)散布了它.然后您有了数据库名
>
Dear All
i knew it it is stupid question but i don''t know so ask you all expert need help
try
{
using (MySqlConnection con = new MySqlConnection(txtOtherConStr.Text.Trim()))
{
foreach()
{
}
}
}
This is my code my connection string in the txtOtherConStr.Text(data source=localhost; uid=root; pwd=root; database=Hr;)
i want to database=Hrhow can i get pls help meeeeeee
解决方案
I am not a Regex expert but this pattern would be a good start I guess:database=(.*?)
. You can then useMatch.Groups
property to get the database name.
First Take txtOtherConStr.Text in a string like string st=txtOtherConStr.Text.Trim() then split it by (;) like string []st1=st.split(;) then You have st1[0],st1[1],t1[2],st1[3]..Now find string which have database . i think itis st1[3] now spilt it again by (=).. then u have the databasename
这篇关于如何使用C#从连接字符串中过滤数据库名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文