2012 m. gegužės 27 d., sekmadienis

RowDataBound with LINQ

Jeigu GridView pakraunamas duomenimis iš DataTable, tada RowDataBound įvykyje galime paimti bet kurią pakrautų duomenų eilutę taip:

Dim oRW As DataRow = CType(e.Row.DataItem, DataRowView).Row

Jeigu GridView pakrauname duomenimis iš LINQ, būtina sukurti klasės objektą, kad būtų aišku, kokie duomenys imami. Kitaip - jie bus traktuojami kaip anoniminiai.

Friend Class TrainSlfView
Public Property TrID As Integer
Public Property TrDate As DateTime
Public Property Name As String
Public Property TrDuration As Decimal
Public Property TrDurationType As String
Public Property TrCost As Decimal
Public Property TrLocation As String
Public Property TrTitle As String
Public Property TrNotes As String
End Class

Duomenų pakrovimas:

Dim oTrain = (From t In oDB.TrainingSelfs
Join em In oDB.TrainingEmployeeSelfs On em.TrID Equals t.TrID
Join emp In oDB.Employees On em.TrEmpID Equals emp.Id
Where t.TrStatus = 0
Select New TrainSlfView With {.TrID = t.TrID, .TrDate = t.TrDate, .Name = emp.Name, .TrDuration = t.TrDuration, .TrDurationType = t.TrDurationType, .TrCost = t.TrCost, .TrLocation = t.TrLocation, .TrTitle = t.TrTitle, .TrNotes = t.TrNotes}).ToList




grdTrainingView.DataSource = oTrain
grdTrainingView.DataBind()

 Tada RowDataBound įvykyje TrID paimsime taip:

Dim oRW As TrainSlfView = CType(e.Row.DataItem, TrainSlfView)
e.Row.Attributes.Add("TrID", oRW.TrID)

hlEdit.NavigateUrl = "javascript:editRow(" & oRW("ID") & ",'" & e.Row.ClientID & "')"

2012 m. gegužės 10 d., ketvirtadienis

How to import data from one MS SQL database to other

Solution:

1. Create table structure



2. Import data

2012 m. gegužės 1 d., antradienis

How to see div element in ASP.NET program code

Problem: I have same div elements in my document. I would like to add values programmically, but I can't see that div.

Solution: Add attribute runat="server" to that div elements.

Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF

Problem: I worked with VB ASP.NET LINQ. I added new table in LINQ model and found this error message:

Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF.

Solution:


http://alexeyzimarev.blogspot.com/2011/03/identityinsert-is-set-to-off-issue.html