回复 4楼 Maick
SQLSERVERUtil完整代码是这样的,能帮我结合了改改吗?
class SQLSERVERUtil
{
private static SoundPlayer simpleSound;
public static string errorpath = "\\Flash Disk\\error.wav";
public static string rightpath = "\\Flash Disk\\right.wav";
private static SqlConnection conn = GetConnection();
private static SqlCommand cmd = null;
public static SqlConnection GetConnection()
{
string connectionString = "";
try
{
SQLSERVERconfig serverConfig = FileUtil.GetConfiguration();
if (serverConfig.server!=null)
{
connectionString = "Data Source=" + MainForm.userform.option.ReadString("Info", "IP", "") ;
}
if (serverConfig.database!=null)
{
connectionString = connectionString + ";initial catalog=" + MainForm.userform.option.ReadString("Info", "DataName", "");
}
if (serverConfig.uid != null)
{
connectionString = connectionString + ";UID=" + MainForm.userform.option.ReadString("Info", "User", "");
}
if (serverConfig.pwd != null)
{
connectionString = connectionString + ";PWD=" + MainForm.userform.option.ReadString("Info", "Password", "");
}
}
catch (System.Exception ex)
{
throw new System.Exception(ex.Message);
}
SqlConnection connection = null;
try
{
connection = new SqlConnection(connectionString);
}
catch (System.Exception ex)
{
throw new System.Exception(ex.Message);
}
return connection;
}