Gridview and Linq to SQL

Asked

Viewed 22 times

0

I am trying to change data in a Gridview using a Datasource Linq to SQL Context:

I created a table in SQL: Bancoid int Autoincrement Banconumero char(3) Banconome varchar(30)

I created a Linq to SQL class and includes access to that table.

In the Data Source window I read the Data Context Object for my table. I created a form and added a Datagridview. In Datagridview I changed the Datasource for this data source connection.

Datagridview recognized the columns of my table.

The selection automatically created a System.Windows.Forms.Bindingsource

When I run and try to add data in the table, in Datagridview it is as if the data were being added, except for the Bancoid that is always with value 0.

But when I close the form and open again I see that the data was not saved in the SQL table.

What needs to be done to function?

  • After the changes you persisted these changes made in the database?

  • I’m migrating from VB6 and learning C# now. On VB6 this was automatic. Which way should I go to get the data saved in my table? I would like to edit the columns directly in Datagridview.

  • It would be in your data context to use the method Savechanges() This link has an example https://stackoverflow.com/questions/3766417/save-changes-in-linq-to-sql But each case may require some aspects with regard to the context observing the changes. Since you didn’t have any code about how it was done, it is difficult to help in a better way

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.