我有一個SQL Express文件和一個表People。人們有六或七列,但沒有行。數據庫是我的Visual Studio 2010 Express項目中的一個資源。我試圖用這個代碼連接:這個資源/表有什麼問題?
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS; AttachDbFilename=C:\\someLocation\\someDatabase.mdf; Integrated Security=True; User Instance=True ");
conn.Open();
SqlCommand cmd = new SqlCommand(@"select * from People;", conn);
不過,我收到以下錯誤:
Invalid object name 'People'.
基於一些休閒谷歌上搜索我想先擁有dbo表名(DBO .People)但這並沒有解決問題。我可能會做錯什麼?
編輯:這裏是Visual Studio中的示出的數據庫中的屏幕截圖,它的結構和內容,以及它在解決方案瀏覽器存在:
你在哪一行得到錯誤? – 2012-02-09 09:25:22
你可以發表表格的確切結構嗎? – joshhendo 2012-02-09 09:27:05
@Adel:如果我用'SqlCommand'對象註釋掉那行,那麼我不會得到這個錯誤。 – dotancohen 2012-02-09 09:31:40