我在尝试连接到本地数据库时遇到问题。我已经尝试了该网站上其他帖子的一些建议,但无济于事。任何帮助将不胜感激。以下是我到目前为止所拥有的。
private void button1_MouseClick(object sender, MouseEventArgs e)
{
try
{
sConnection = "Server=(localdb)\Database1;Integrated Security=true;";
dbConn = new SqlConnection(sConnection);
dbConn.Open();
sql = "SELECT * FROM Table2 ORDER" +
"BY Customer name ASC;";
dbCmd = new SqlCommand();
dbCmd.CommandText = sql;
dbCmd.Connection = dbConn;
dbReader = dbCmd.ExecuteReader();
while (dbReader.Read())
{
aMember = new member(dbReader["Name2"].ToString());
this.listBox1.Items.Add(aMember);
}
dbReader.Close();
dbConn.Close();
}
catch (System.Exception exc)
{
MessageBox.Show(exc.Message);
}
}