I have a data entry Winforms App in VS2010. Along with an Entity Data Model (.edmx) that is connected to a SQL Compact Database. In this database I have a table Ticket that I am trying to make an insert into.
On my form, I have all my controls DataBindings property setup and pointing to the correct fields in the database.
I am trying to take the values from the controls on the form and add one non-databound field and save the ticket.
Here is my code:
private void btnSave_Click(object sender, EventArgs e)
{
this.TS = new TicketService();
Ticket t = (Ticket)ticketBindingSource.DataSource;
t.DateEntered = Datetime.Now;
TS.SaveTicket(t);
}
I am getting an error with Converting the TicketBindingSource to the Ticket Object.
Anyone know how to do this conversion?
Thanks
Edit: I am not sure if I was clear enough on my issue, I do not believe this is uncommon. All I am trying to do is take the data from my databound controls, place it into a variable, add a non-databound data (e.g. t.DateEntered = DateTime.Now like in the example above) and then Save the data to the database.
I have done this in VB.Net, but VB.Net does this conversion from the DataSource to the Variable automatically. Here is the VB.Net code:
Dim t = ticketBindingSource.DataSource
t.DateEntered = DateTime.Now()
TicketService.SaveTicket(t)
C# does not do this automatically, it throws an error.
I don’t know what do you want exactly, but this is a very good example:
Insert, Update and Delete using Entity Framework
I hope help you.
Happy code !