I decided to try out C# for the first time after using VB.net.
Out of curiousity, when I used VB.net I had :
Dim conn As OleDbConnection = New OleDbConnection("Provider=""****"";user id=" & strUserID & ";data source=" & strDatabase & ";password=" & strPssWd)
When trying to convert this format to C# I did the following:
string strAccessConn = "Provider=****;user id=" & strUserID & ";data source=" & strDatabase & ";password=" & strPssWd
However, my strUserId, strDatabase and strPssWd where saved in my Module.vb for VB.net like so:
Module Module1
Friend strDatabase As String = "****"
Friend strUserID As String = "****"
Friend strPssWd As String = "****"
End Module
How do I make the Module in C# (an example would be helpful) Thanks!
FYI: I was told C# Equivalent for VB 'module' was a duplicate.
However the formatting and process of their post isn't equivalent to mine. I am asking a module based on database connection.
You can put constants in a public static class
like this:
public static class MyConnectionStringConstants
{
public const string strDatabase = "****";
public const string strUserID = "****";
public const string strPssWd = "****";
}
To use it, you will need to refer to the constants like this:
string strAccessConn = "Provider=****;user id=" + MyConnectionStringConstants.strUserID + ";data source=" + MyConnectionStringConstants.strDatabase + ";password=" + MyConnectionStringConstants.strPssWd
BTW, in C#, you concatenate strings using the +
operator, not the &
operator.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.