C
C#7mo ago
Vasshi

Help display 2 tables from Sql Server in WPF C#

Please help me display 2 tables from my database linked via ADO.net. I’ve been trying to figure out how to do this for 3 hours now, the videos don’t help and there are no good programmers around me.
No description
No description
No description
28 Replies
leowest
leowest7mo ago
what this returns?
No description
leowest
leowest7mo ago
I don't speak your language so its a bit hard to read the code but I will try to help if u can show those classes it would help
SpReeD
SpReeD7mo ago
It's possible to use cyrillic in C# code? - That's kind of a obfuscation 😄 However, it's hard to read your ERD.
Vasshi
VasshiOP7mo ago
Hello, it displays the table Orders (Заказы), where orderid1 (Идзаказа1), flightid1 (Идрейса2), transportid2 (Идтранспорта), orderdate (Датазаказа), number of passengers (Колвопассажиров, departure_time (ВремяОтправения), arrivaltime (ВремяПрибытия), flight_cost (Стоимость рейса)
leowest
leowest7mo ago
it would help if u show me the code so I can see the type etc and properly help u I understand you're getting it from ado, I am unsure what you're performing in that class that requires calling tolist so I would like to look at the code to further understand what I am dealing with
Vasshi
VasshiOP7mo ago
You can haha, I myself would like to learn English to write code and generally communicate with people.
leowest
leowest7mo ago
preferable $paste to the link below instead of images, or if u have a github of that project
MODiX
MODiX7mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Vasshi
VasshiOP7mo ago
I can send a screenshot with the code for the entire application
leowest
leowest7mo ago
screenshot + code = bad use the link above or github pls
Vasshi
VasshiOP7mo ago
okay
leowest
leowest7mo ago
imagine if I wanted to copy part of your code to change and show u what is wrong, I can't from an image
Vasshi
VasshiOP7mo ago
xd I'll upload it to Git Hub now
leowest
leowest7mo ago
sounds great 🙂
Vasshi
VasshiOP7mo ago
Having trouble uploading to Github, what if I upload to Google Drive?
leowest
leowest7mo ago
use the website above its very simple
leowest
leowest7mo ago
Vasshi
VasshiOP7mo ago
BlazeBin - yxhrahlsdqlc
A tool for sharing your source code with the world!
leowest
leowest7mo ago
@Vasshi u missed this one Экскурсионный_ТранспортEntities which is the one I want to see lol
Vasshi
VasshiOP7mo ago
BlazeBin - pzycvtpqjawu
A tool for sharing your source code with the world!
leowest
leowest7mo ago
huh you said ur using ado, but that file is EntityFramework well at least it makes sense now why ur calling ToList 🙂 can u show me the model for Заказы (the class) ADO would be what you're doing on MainWindow.xaml.cs so I also need to understand whether u want to do this with ADO or EntityFramework
Vasshi
VasshiOP7mo ago
BlazeBin - dkzluizbdmdz
A tool for sharing your source code with the world!
Vasshi
VasshiOP7mo ago
I need to display 2 tables in WPF via ADO
leowest
leowest7mo ago
ok so this ЭкскурсионныйТранспортEntities has to go away that is not related to ADO ```cs DataTable Select(string SelectSQL) { DataTable table = new DataTable("dataBase"); SqlConnection sqlConnection = new SqlConnection(@"data source=DESKTOP-I4953GG\SQLEXPRESS;initial catalog=ЭкскурсионныйТранспорт;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""); sqlConnection.Open(); SqlCommand sqlCommand = sqlConnection.CreateCommand(); sqlCommand.CommandText = SelectSQL; SqlDataAdapter adapter = new SqlDataAdapter(sqlCommand); adapter.Fill(table); return table; }
All you need, would be to use that method with the right SQL query to populate your datagrid.
All you need, would be to use that method with the right SQL query to populate your datagrid.
cs var result = Select(/* the query to retrieve the data u need here/); DtgZak.ItemsSource = result.DefaultView;
u would have to removed all of these
u would have to removed all of these
xml <DataGrid x:Name="DtgZak" Grid.Row="2" ColumnWidth="
" AutoGenerateColumns ="False"> <DataGrid.Columns> <DataGridTextColumn Header="Иддолжностиработ2" Binding="{Binding Составзаказа.Иддолжностиработ2}"></DataGridTextColumn> <DataGridTextColumn Header="Ид рейса" Binding="{Binding Идрейса2}"></DataGridTextColumn> <DataGridTextColumn Header="Колво пассажиров" Binding="{Binding Колвопазажиров}"></DataGridTextColumn> <DataGridTextColumn Header="Время Отправления" Binding="{Binding ВремяОтправления}"></DataGridTextColumn> <DataGridTextColumn Header ="Время Прибытия" Binding="{Binding ВремяПрибытия}"></DataGridTextColumn> <DataGridTextColumn Header="Дата заказа" Binding="{Binding Датазаказа}"></DataGridTextColumn> </DataGrid.Columns> </DataGrid>
Into
Into
xml <DataGrid x:Name="DtgZak" Grid.Row="2" ColumnWidth="*" AutoGenerateColumns ="True" /> ``` also make sure u read $sqlinjection
MODiX
MODiX7mo ago
Always parametrize queries! Do not concatenate the query, like in this example:
// Do NOT do this
string query = "SELECT * FROM users WHERE username='" + UserName + "';";
...
// Do NOT do this
string query = "SELECT * FROM users WHERE username='" + UserName + "';";
...
Instead, always parameterize your queries. Look up the documentation for your database library. If you are using System.Data.SqlClient, refer to this example.
Imgur
Vasshi
VasshiOP7mo ago
Thank you very much for your help, I will use it in the near future
leowest
leowest7mo ago
is the grid working now?
Vasshi
VasshiOP7mo ago
I haven't checked it yet, I just got home
Want results from more Discord servers?
Add your server