stringConnectionString = "Data Source = 192.168.0.222; Initial Catalog= ;User ID=xxxxxxx;Password=yyyyyy";
这是我的连接字符串我不知道如何分配连接字符串&这是我的档案位置
d:\ Gurusoft \的Gowtham \工作\ G9HCMS \ G9Collaboration \的DataProvider \ clsPatients.cs
我的整个代码
public partial class MainWindow:Window { 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());
}
}
}
}
如何设置此连接字符串
答案 0 :(得分:0)
尝试在连接字符串
之前添加@new SQlConnection(@"Data Source=HOGAR\SQLEXPRES;Init...");
或使用\而不是\
new SQlConnection("Data Source=HOGAR\\SQLEXPRES;Init...");