简体   繁体   English

如何使用连接字符串并显示无法识别的转义序列?

[英]how to use connection string & it shows unrecognized escape sequence?

stringConnectionString = "Data Source = 192.168.0.222; Initial Catalog= ;User ID=xxxxxxx;Password=yyyyyy";

this is my connectionstring i don't know how to assign connection string & this is my file location 这是我的连接字符串,我不知道如何分配连接字符串,这是我的文件位置

D:\\Gurusoft\\Gowtham\\work\\G9HCMS\\G9Collaboration\\DataProvider\\clsPatients.cs D:\\ Gurusoft \\ Gowtham \\ work \\ G9HCMS \\ G9Collaboration \\ DataProvider \\ clsPatients.cs

my entire code 我的整个代码

public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); 公共部分类MainWindow:窗口{public MainWindow(){InitializeComponent(); } }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        string stringConnectionString = null;           
        DataSet objDataSet;
        SqlCommand objSqlCommand;


        try
        {
            int intNum = 0;
            objDataSet = new DataSet();
            objSqlCommand = new SqlCommand();
            stringConnectionString = (@"Data Source = 192.xxx.0.yyy; Initial Catalog=C:User\G9HCMS\clsPatients.cs;Persist Security Info=true;User ID=xxxx;Password=yyyyy");
            SqlConnection objSqlConnection = new SqlConnection(stringConnectionString);

            {

                if (objSqlConnection != null)
                {
                    objSqlConnection.Open();
                    SqlDataAdapter objSqlDataAdapter = new SqlDataAdapter("select * from MR_Patients", objSqlConnection);
                    // objSqlCommand.Connection = objSqlConnection;                                                                
                    objSqlDataAdapter.Fill(objDataSet);

                    for (intNum = 0; intNum <= objDataSet.Tables[0].Rows.Count - 1; intNum++)
                    {
                        MessageBox.Show(objDataSet.Tables[0].Rows[1].ItemArray[1].ToString());

                    }
                }
                else
                {
                    objSqlConnection.Close();
                    MessageBox.Show("connection Error");

                }
            }
        }
        catch (Exception objException)
        {
            MessageBox.Show("Exception" + objException.ToString());


        }
    }
}

} }

how to set this connection string 如何设置此连接字符串

Try adding @ before connection string 尝试在连接字符串之前添加@

new SQlConnection(@"Data Source=HOGAR\SQLEXPRES;Init...");

Or use \\ instead of \\ 或使用\\代替\\

new SQlConnection("Data Source=HOGAR\\SQLEXPRES;Init...");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM