2017-11-14 9 views
-4

私のコースワーク用のアプリケーションを作成していますが、完了の方法を理解できないことが1つあります。これは、データベースからのデータでwinforms内のテーブルを作成する必要があります。データベースからの値を使用してC#で表を作成

表の行と列の曜日は週単位である必要があります。私はデータベースからデータを取得してテーブルに記入することを忘れました。この表は、医師の手術における患者の予定です。

+2

、Googleのデータベース101と開始そこ – Steve

+0

可能重複から: https://stackoverflow.com/questions/5483320/c-bind-datagridview-to-a-database-file-in-the-application-directory –

+0

Uあなたのデータベースからデータテーブルを埋めることができますし、Uはリストのようにこのデータテーブルを使うことができます –

答えて

0

まず、SQL Serverデータベースに焦点を絞ってから、C#フォームを重視する必要があるようです。

セットアップあなたのテーブルにはこれに似た形があるので:あなたの真のデータの実際のタイムスタンプを持つgetdate()を置き換えます

select 
getdate() as Curr_Date 
,datename(dw,getdate()) as Weekday_Name 
,datepart(dw,getdate()) as Weekday_Number 
,case when datepart(dw,getdate()) = 1 then 'Your Column Value Goes Here' end as Sunday 
,case when datepart(dw,getdate()) = 2 then 'Your Column Value Goes Here' end as Monday 
,case when datepart(dw,getdate()) = 3 then 'Your Column Value Goes Here' end as Tuesday 
,case when datepart(dw,getdate()) = 4 then 'Your Column Value Goes Here' end as Wednesday 
,case when datepart(dw,getdate()) = 5 then 'Your Column Value Goes Here' end as Thursday 
,case when datepart(dw,getdate()) = 6 then 'Your Column Value Goes Here' end as Friday 
,case when datepart(dw,getdate()) = 7 then 'Your Column Value Goes Here' end as Saturday 

を。 'Your Column Value Goes Here'を実際のデータ値に置き換えます。
最後に、C#フォームで特定のセルをキャプチャする必要があります。

あなたの投稿をもう一度読みました。それはあなたが行の時間が欲しいように見えますか?もしそうなら、このような何かしてみてください:私は寛大な感じと、実際にSQLを書いて楽しんでいますので...

create table Schedule 
(
Person varchar(15) 
,Appointment datetime 
) 
; 
insert into Schedule values 
('John Doe','2017-11-20 9:25:00'), 
('Jane Doe','2017-11-22 9:15:00'), 
('Michael','2017-11-24 9:25:00'), 
('Sam','2017-11-26 9:15:00') 
; 

create table Time_Table 
(
Start_Time time, 
End_Time time, 
Time_Name Varchar(20) 
) 
; 
insert into Time_Table values 
('9:00' , '9:10' , '9:10 - 9:10' ) 
,('9:10' , '9:20' , '9:10 - 9:20' ) 
,('9:20' , '9:30' , '9:20 - 9:30' ) 
,('9:30' , '9:40' , '9:30 - 9:40' ) 
,('9:40' , '9:50' , '9:40 - 9:50' ) 
,('9:50' , '10:00' , '9:50 - 10:00') 
; 

select 
a.Time_Name 
,max(case when datepart(dw,b.Appointment) = 1 then b.Person end) as Sunday 
,max(case when datepart(dw,b.Appointment) = 2 then b.Person end) as Monday 
,max(case when datepart(dw,b.Appointment) = 3 then b.Person end) as Tuesday 
,max(case when datepart(dw,b.Appointment) = 4 then b.Person end) as Wednesday 
,max(case when datepart(dw,b.Appointment) = 5 then b.Person end) as Thursday 
,max(case when datepart(dw,b.Appointment) = 6 then b.Person end) as Friday 
,max(case when datepart(dw,b.Appointment) = 7 then b.Person end) as Saturday 
from Time_Table a 
LEFT JOIN Schedule b ON cast(b.Appointment as time) between a.Start_Time and a.End_Time 
group by 
a.Time_Name 
order by a.Time_Name 

select 
getdate() as Curr_Date 
,datename(dw,getdate()) as Weekday_Name 
,datepart(dw,getdate()) as Weekday_Number 
,case when datepart(dw,getdate()) = 1 then cast(getdate() as time) end as Sunday 
,case when datepart(dw,getdate()) = 2 then cast(getdate() as time) end as Monday 
,case when datepart(dw,getdate()) = 3 then cast(getdate() as time) end as Tuesday 
,case when datepart(dw,getdate()) = 4 then cast(getdate() as time) end as Wednesday 
,case when datepart(dw,getdate()) = 5 then cast(getdate() as time) end as Thursday 
,case when datepart(dw,getdate()) = 6 then cast(getdate() as time) end as Friday 
,case when datepart(dw,getdate()) = 7 then cast(getdate() as time) end as Saturday 

をこれはあなたの割り当てのSQL Serverのバージョンです。あなたの課題のポイントは、データベースとの相互作用の基礎を学ぶこととはっきりと関係しています。私はここであなたのためのCRUDアプリを構築するつもりはありませんが、これは少なくともあなたが始めるための非常に確かな基礎を与える必要があります。

+0

これは私が望む結果を作りません。クエリを実行すると、現在の日付と日付の1行が表示されます。私のデータに基づくものはありません。 –

+0

これは私が欲しいもののイメージです:https://storage.marks.pw/index.php/s/opeensLmHWA22rn –

+0

正しい。私はあなたの時間を(SQL ServerまたはC#)働かせたいと思っていません。私があなたに与えたことは、すでにデータが保存されていることを前提としています。 Column1をタイムスタンプとして、Column2を値(例:Name)として持つ表として作成します。これは宿題の問題なので、実際に勉強に戻るべきです。あなたの投稿はすでに複数回ダウン投票されています。正直なところ、まだ閉じられていない理由はわかりません。あなたの研究に幸運。 – Andrew

関連する問題