iT邦幫忙

0

ASP.NET + SQL 資料表無法建立關聯

請問以下畫紅圈處書上有資料庫圖表 , 但第二張我的 vs2017+SQL 紅圈處就沒有資料庫圖表 , 這樣資料表就無法建立關聯

https://ithelp.ithome.com.tw/upload/images/20171122/20104326YSsgmXta2r.png

https://ithelp.ithome.com.tw/upload/images/20171122/20104326hYLvjkIZZw.png

You can use Object Explorer to create new database diagrams. Database diagrams graphically show the structure of the database. Using database diagrams you can create and modify tables, columns, relationships, and keys. Additionally, you can modify indexes and constraints.
To create a new database diagram

In Object Explorer, right-click the Database Diagrams folder or any diagram in that folder.
Choose New Database Diagram on the shortcut menu.
The Add Table dialog box appears.
Select the required tables in the Tables list and click Add.
The tables are displayed graphically in the new database diagram.
You can continue to add or delete tables, modify the existing tables, and alter table relationships until the new database diagram is complete.
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
小碼農米爾
iT邦高手 1 級 ‧ 2017-11-22 22:57:58
最佳解答

建議使用 Sql Server Management Studio 來管理資料庫,
可以建立資料庫圖表,用拉線的方式建立關聯,
我記得 Visual Studio 是沒辦法建立資料庫圖表的,
不過可以用 SQL 語法來建立關聯,您可以試試看
http://www.w3school.com.cn/sql/sql_foreignkey.asp

看更多先前的回應...收起先前的回應...
小魚 iT邦大師 1 級 ‧ 2017-11-23 12:29:08 檢舉

好像是有Entity,
不過我沒有在用,
只是接案子有遇過別人這樣做,
稍微瞭解一下需要的時候比較有概念怎麼處理而已.

Entity 又更複雜了
/images/emoticon/emoticon01.gif

alex9453 iT邦新手 2 級 ‧ 2017-11-23 22:09:05 檢舉

你們說的 , 我覺得都蠻複雜的 , 還是下載書上 vs2008 來用 , 看書上做比較看得懂 , 問題是 , 2008 跟現在 2017 是不是差很多 , 2008 的技術 , 跟得上現在潮流嗎 ?

但是我看書上的範例是用 Sql Server Management Studio 在操作,
不是用 Visual Studio 阿,
/images/emoticon/emoticon19.gif
然後 Visual Studio 當然習慣新的會比較好,
功能介面也增進不少。

Sql Server Management Studio
https://ithelp.ithome.com.tw/upload/images/20171123/201068657bENmZ4jii.jpg
Visual Studio
https://ithelp.ithome.com.tw/upload/images/20171123/20106865S4eTzdhsQx.jpg

我看到您的 SQL 怎麼沒有資料庫圖表 這篇,
您一開始用的軟體是對的,
https://ithelp.ithome.com.tw/upload/images/20171123/20106865qkLwPwmGLb.jpg
然後您找不到圖表是因為資料庫沒有建立出來,
看看階層,
https://ithelp.ithome.com.tw/upload/images/20171123/20106865luIesIxiHm.jpg

alex9453 iT邦新手 2 級 ‧ 2017-11-23 23:40:04 檢舉

謝謝你的回答 ,但請問以下儲存出現錯誤訊息是什麼意思 , 還有怎麼在vs2017 ,把建好的資料表叫出來 . 謝謝 !

https://ithelp.ithome.com.tw/upload/images/20171123/20104326RtdpI3p5Df.png

https://ithelp.ithome.com.tw/upload/images/20171123/20104326mNmBoGMAup.png

應該是資料有問題,可以先把資料清掉試試。
這個錯誤通常是關聯的欄位,裡面的值在對應的資料表對應不到。

賽門 iT邦超人 1 級 ‧ 2017-11-24 12:42:07 檢舉

Index不能對齊,兩邊的Primary Key設置不同,無法自動產生關聯,要手動來建立關聯。

alex9453 iT邦新手 2 級 ‧ 2017-11-24 20:36:43 檢舉

謝謝問題解決了, 現在是關聯建好了怎麼拉進 visual studio 中 , 網上查了很多資料 , 都找不到解決辦法 .

https://ithelp.ithome.com.tw/upload/images/20171124/20104326qPZiDStsE7.png

https://ithelp.ithome.com.tw/upload/images/20171124/20104326y4H5aW4QYz.png

alex9453 iT邦新手 2 級 ‧ 2017-11-24 20:39:06 檢舉

下圖我是建了其他資料表 , 上圖不知道怎麼拉進來

Visual Studio 不支援關聯圖表,
但資料庫本身已經有關聯了,
寫程式時,連線字串直接連結 SQL Server 就好。

通常在開發時 Visual Studio 只負責程式,
資料庫不會放在專案內,
SqlDataSource 可以連過去 SQL Server 資料庫。

alex9453 iT邦新手 2 級 ‧ 2017-11-24 21:45:29 檢舉

所以資料表不需要關聯 , 直接用 SqlDataSource 指定資料表就可以是嗎 ?

https://ithelp.ithome.com.tw/upload/images/20171124/20104326sdK0sOFCrC.png

alex9453 iT邦新手 2 級 ‧ 2017-11-24 23:24:22 檢舉

怎麼無法輸入資料 , 一直錯誤 , 網上也找不到答案

https://ithelp.ithome.com.tw/upload/images/20171124/20104326g1pp7S28fj.png

這是兩件事喔,資料表關連或不關連,SqlDataSource 都看可以連接,我的意思是可以不在 vs 管理資料庫,新增資料表和關連圖,都到 ssms 那裡,vs 很單純的寫程式。

應該是學號重覆了

0
sonia
iT邦新手 2 級 ‧ 2017-11-23 14:34:38

建DataSet 吧,也是拉一拉就好,Entity 太複雜的話用Linq To SQL 也很簡易,也是拉一拉就好

0
賽門
iT邦超人 1 級 ‧ 2017-11-24 12:42:55

盡信書,不如無書。

我要發表回答

立即登入回答