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

本文关键字:识别 转义序列 显示 连接 何使用 字符串 | 更新日期: 2023-09-27 18:01:19

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

这是我的连接字符串我不知道如何分配连接字符串&这是我的文件位置

D: ' Gurusoft ' Gowtham ' '工作G9HCMS ' G9Collaboration ' DataProvider ' clsPatients.cs

整个代码

公共局部类MainWindow: Window{公共主窗口(){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());

        }
    }
}

}

如何设置此连接字符串

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

尝试在连接字符串前添加@

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

或者用'代替'

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