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.
28 Replies
what this returns?
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
It's possible to use cyrillic in C# code? - That's kind of a obfuscation 😄
However, it's hard to read your ERD.
Hello, it displays the table Orders (Заказы), where orderid1 (Идзаказа1), flightid1 (Идрейса2), transportid2 (Идтранспорта), orderdate (Датазаказа), number of passengers (Колвопассажиров, departure_time (ВремяОтправения), arrivaltime (ВремяПрибытия), flight_cost (Стоимость рейса)
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
You can haha, I myself would like to learn English to write code and generally communicate with people.
preferable $paste to the link below instead of images, or if u have a github of that project
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!
I can send a screenshot with the code for the entire application
screenshot + code = bad
use the link above or github pls
okay
imagine if I wanted to copy part of your code to change and show u what is wrong, I can't from an image
xd I'll upload it to Git Hub now
sounds great 🙂
Having trouble uploading to Github, what if I upload to Google Drive?
use the website above
its very simple
BlazeBin - yxhrahlsdqlc
A tool for sharing your source code with the world!
@Vasshi u missed this one Экскурсионный_ТранспортEntities
which is the one I want to see lol
BlazeBin - pzycvtpqjawu
A tool for sharing your source code with the world!
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
BlazeBin - dkzluizbdmdz
A tool for sharing your source code with the world!
I need to display 2 tables in WPF via ADO
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;
}
cs
var result = Select(/* the query to retrieve the data u need here/);
DtgZak.ItemsSource = result.DefaultView;
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>
xml
<DataGrid x:Name="DtgZak" Grid.Row="2" ColumnWidth="*" AutoGenerateColumns ="True" />
```
also make sure u read $sqlinjection
Always parametrize queries!⠀
Do not concatenate the query, like in this example:
Instead, always parameterize your queries. Look up the documentation for your database library. If you are using
System.Data.SqlClient
, refer to this example.Thank you very much for your help, I will use it in the near future
is the grid working now?
I haven't checked it yet, I just got home