I'm using datagridview for CRUD operations.
Earlier when I used ADO.net and later when I moved to EF i successfully was committing every command that I wanted. Insert, update or delete.
Suppose i want to update first row, or four row and eleven row, and what if i delete a second, and also what if i need to add a new row. All that in same time using datagridview.
Then after all this modification i just need to call DA.Update(DS) or in EF SaveChanges and all my data will be saved. In first two scenario i can do exactly that!
Example for first two: ADO.NET AND EF6
I have done this in the following way :
ADO.NET:
Dim command As New SqlCommand
command = New SqlCommand(query, conn)
command.CommandTimeout = 200
ds = New DataSet
SQLDA = New SqlDataAdapter(command)
SQLDA.Fill(ds)
Dim cb As New SqlCommandBuilder(SQLDA)
Dim bs As New BindingSource
bs .DataSource = ds.Tables(0)
DGV.DataSource = bs
button_clik
SQLDA.UPDATE(ds) 'save all changes i have made
EF
db = New _Context
db.tPROMs.Load()
Dim b = db.tPROMs.Local.ToBindingList
b.AllowEdit = True
b.AllowNew = True
b.AllowRemove = True
Dim bs As New BindingSource
bs.DataSource = b
DGV.DataSource = bs
button_clik
db.SaveChanges() 'save all changes i have made
Now how can i save data directly from the grid using DAPPER.NET or ServiceStack.OrmLite
So far I have done this over ADO.NET and later with EF6. But for better performance now I want to do with Dapper.net or ServiceStack.OrmLite.
DAPPER.NET
???????
ServiceStack.OrmLite
???????
I'm having hard time following your code but dapper syntax for insert should be like this:
using (var conn = new SqlConnection("YourConnString"))
{
return conn.Execute(query, instaceToInsert);
}
Dapper will automatically map the properties in your model to fields in your query...
So for example if you insert query is:
INSERT INTO Users (LastName, FirstName) VALUES (@LastName, @FirstName)
then your model needs to be something like:
public class User
{
public string LastName { get; set; }
public string FirstName { get; set; }
}
And then replace instanceToInsert with instance of user...
using (var conn = new SqlConnection("YourConnString"))
{
return conn.Execute(query, new User {LastName = "John", FirstName = "Doe"});
}
Here is the VB.NET version:
Using conn = New SqlConnection("YourConnString")
Return conn.Execute(query, instaceToInsert)
End Using
Public Class User
Public Property LastName() As String
Public Property FirstName() As String
End Class
Using conn = New SqlConnection("YourConnString")
Return conn.Execute(query, New User() With { .LastName = "John", .FirstName = "Doe"})
End Using