Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
A

ADSCNET

@ADSCNET
About
Posts
24
Topics
7
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Not Getting cell value for selected row of GridView
    A ADSCNET

    Hi, I'm not able to get the cell value for the selected row in the gridview, the code in the aspx page:

    <asp:GridView runat="server" ID="gvElMaster" PageSize="5" Width="100%" ItemType="EMS.Ems_ElMaster"
    DataKeyNames="ElMasterID" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
    SelectMethod="GetElMaster" HeaderStyle-VerticalAlign="Middle"
    HeaderStyle-HorizontalAlign="Center" CaptionAlign="Top" CellPadding="4" GridLines="None" ForeColor="#333333"
    OnSelectedIndexChanged="gvElMaster_SelectedIndexChanged">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
    <asp:DynamicField DataField="ElName" />
    <asp:DynamicField DataField="ElStartRegDate" />
    <asp:DynamicField DataField="ElEndRegDate" />
    <asp:DynamicField DataField="ElDate" />
    <asp:CommandField ShowSelectButton="True" SelectText="Select" CausesValidation="False" InsertVisible="False" ShowCancelButton="False"></asp:CommandField>
    </Columns>
    </asp:GridView>

    code behind:

    Public Function GetElMaster() As IQueryable(Of Ems_ElMasterClass)
    Return _db.DbSet_ElMasters
    End Function

    Protected Sub gvElMaster_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvElMaster.SelectedIndexChanged
    MsgBox(gvElMaster.SelectedIndex)
    MsgBox(gvElMaster.SelectedValue.ToString)
    MsgBox(gvElMaster.SelectedRow.Cells(1).Text)
    MsgBox(gvElMaster.SelectedRow.Cells(2).Text)
    MsgBox(gvElMaster.SelectedRow.Cells(3).Text)
    End Sub

    I get empty text from all the cells Development envirunment is: - VS 2012 - Asp.net 4.5 - CodeFirst aproach Thanks for the help

    Visual Basic csharp asp-net visual-studio linq sysadmin

  • Date value not showing in the calendar with HTML5 support
    A ADSCNET

    I have a Form View has a text field in the , the text field binded to a 2 way binded control, code as follow:

    and I'm using TextMode as Date which will result in displaying the calender in the browser. in the Model Entity class I'm defining the DOB as:

    Public Property DOB() As Date?

    The problem: When using Google Chrome or Opera which they are excellent in handling & compatible with HTML5 elements, the txtDOB field doesn't show the date data value which binded from the db, what displayed instead is: 1- in Chrome, displays yyyy-mm-dd, which is the date format iam using 2- in Opera, the txtbox is empty. Both browsers displays the calendar when clicked on the field. Why the bounded date data not shown in the text field also not marked/selected when the calendar opened? Note: in IE I see it as normat txtField with the date value binded from the db, of course no calendar view coz IE ver 9 doesn't support fully HTML5 which results to not understand the tag (TextMode="Date") Used technology: - VS 2012 - Entity Framework 4.5 Thanks for the help in advance

    Visual Studio 2015 & .NET 4.6 help html database visual-studio question

  • How to do this Relationship in Entity Framework using DataAnnotation not Fluent API
    A ADSCNET

    I am submitting the answer I found so it could help whoever faced the same problem. in the Customer class need to add 2 lines for each property has a relation with this Customer class like Marital Status where we should get the list from the MaritalStatus table and save the selected value only in the Customer table:

    <DefaultSettingValue("0")>
    Public Property MaritalStatusID() As Integer?
    Public Overridable Property MaritalStatus() As MaritalStatusClassTable ' This will generate a FK in the Customer table and populate the relationship.

    <DefaultSettingValue("0")>
    Public Property Addr_AreaID() As Integer?
    Public Overridable Property AreaList() As AreaListClassTable

    <DefaultSettingValue("0")>
    Public Property Wrk_OccupationID() As Integer?
    Public Overridable Property Occupation() As OccupationClassTable

    Then in the Customer FormView (if you are using FormView) you need only to define a SelectMethod function where it should return IEnumerable(Of xxxx) list of data from its master table. Note: I think the ID property which was created in the Customer class (Addr_AreaID(), MaritalStatusID(), Wrk_OccupationID()) should be the same ID of the PK in its master table. HTH.

    Visual Studio 2015 & .NET 4.6 csharp database linq sales xml

  • How to do this Relationship in Entity Framework using DataAnnotation not Fluent API
    A ADSCNET

    Yes correct. But still I'm stuck & looking for the answer :)

    Visual Basic csharp database linq sales xml

  • How to do this Relationship in Entity Framework using DataAnnotation not Fluent API
    A ADSCNET

    True .. but (frazzle-me) suggested to submit it in the VB forum so I may get the answer .. so I thought it's ok to do that. Anyhow thanks for the info.

    Visual Basic csharp database linq sales xml

  • How to do this Relationship in Entity Framework using DataAnnotation not Fluent API
    A ADSCNET

    Dear All, I have 6 tables created from a class using EF Code First approach, and I'm wondering how to do the relationship between the tables using DataAnnotation, classes as follow:

    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Web

    Imports System.ComponentModel.DataAnnotations
    Imports System.ComponentModel.DataAnnotations.Schema

    Public Class Customer
    <Key, ScaffoldColumn(False)>
    Public Property CustomerID() As Integer

    <Display(Name:="File No"), StringLength(6)>
    Public Property CustomerFileNo() As String
    
    <Required(ErrorMessage:="First Name is required")>
    <Display(Name:="First Name"), StringLength(20)>
    Public Property FirstName() As String
    
    <Display(Name:="Last Name"), StringLength(20)>
    Public Property LastName() As String
    
    <Display(Name:="Street"), StringLength(40)>
    Public Property Addr\_StreetName() As String
    
    <DefaultSettingValue("0")>
    Public Property MaritalStatusID() As Integer
    
    <DefaultSettingValue("0")>
    Public Property Addr\_AreaID() As Integer
    
    <DefaultSettingValue("0")>
    Public Property Wrk\_OccupationID() As Integer
    

    End Class

    Public Class MaritalStatus
    <Key, ScaffoldColumn(False)>
    Public Property MaritalStatusID() As Integer

    <Required(ErrorMessage:="Name Required")>
    <Display(Name:="Marital Status"), StringLength(10)>
    Public Property MaritalName() As String
    
    <DefaultSettingValue("1")>
    Public Property RecStatus() As Boolean
    

    End Class

    Public Class Area
    <Key, ScaffoldColumn(False)>
    Public Property AreaID() As Integer

    <Required(ErrorMessage:="Name Required")>
    <Display(Name:="Area Name"), StringLength(30)>
    Public Property AreaName() As String
    
    <DefaultSettingValue("1")>
    Public Property RecStatus() As Boolean
    

    End Class

    Public Class Occupation
    <Key, ScaffoldColumn(False)>
    Public Property OccupationID() As Integer

    Public Property OccupationName() As String
    

    End Class

    Public Class InvoiceHdr
    <Key, ScaffoldColumn(False)>
    Public Property InvoiceID() As Integer

    Public Property InvoiceNo() As String
    Public Property Amount() As Integer
    
    Public Property CustomerID As Integer
    

    End Class

    Visual Basic csharp database linq sales xml

  • How to do this Relationship in Entity Framework using DataAnnotation not Fluent API
    A ADSCNET

    Yes I did, what happened after I changed my module that it was expecting me to enter the MaritalStaus data from the Customer form it self & when I tried to use BindItem it gave me error like the value is not listed .... I'll try the VB forum. Thanks again.

    Visual Studio 2015 & .NET 4.6 csharp database linq sales xml

  • How to do this Relationship in Entity Framework using DataAnnotation not Fluent API
    A ADSCNET

    Unfortunately it didn't work.

    Visual Studio 2015 & .NET 4.6 csharp database linq sales xml

  • How to do this Relationship in Entity Framework using DataAnnotation not Fluent API
    A ADSCNET

    Thanks for ur quick reply But do you mean to replace my code with your code or add your code after my code line?

    Visual Studio 2015 & .NET 4.6 csharp database linq sales xml

  • How to do this Relationship in Entity Framework using DataAnnotation not Fluent API
    A ADSCNET

    Dear All, I have 6 tables created from a class using EF Code First approach, and I'm wondering how to do the relationship between the tables using DataAnnotation, classes as follow:

    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Web

    Imports System.ComponentModel.DataAnnotations
    Imports System.ComponentModel.DataAnnotations.Schema

    Public Class Customer
    <Key, ScaffoldColumn(False)>
    Public Property CustomerID() As Integer

    <Display(Name:="File No"), StringLength(6)>
    Public Property CustomerFileNo() As String
    
    <Required(ErrorMessage:="First Name is required")>
    <Display(Name:="First Name"), StringLength(20)>
    Public Property FirstName() As String
    
    <Display(Name:="Last Name"), StringLength(20)>
    Public Property LastName() As String
    
    <Display(Name:="Street"), StringLength(40)>
    Public Property Addr\_StreetName() As String
    
    <DefaultSettingValue("0")>
    Public Property MaritalStatusID() As Integer
    
    <DefaultSettingValue("0")>
    Public Property Addr\_AreaID() As Integer
    
    <DefaultSettingValue("0")>
    Public Property Wrk\_OccupationID() As Integer
    

    End Class

    Public Class MaritalStatus
    <Key, ScaffoldColumn(False)>
    Public Property MaritalStatusID() As Integer

    <Required(ErrorMessage:="Name Required")>
    <Display(Name:="Marital Status"), StringLength(10)>
    Public Property MaritalName() As String
    
    <DefaultSettingValue("1")>
    Public Property RecStatus() As Boolean
    

    End Class

    Public Class Area
    <Key, ScaffoldColumn(False)>
    Public Property AreaID() As Integer

    <Required(ErrorMessage:="Name Required")>
    <Display(Name:="Area Name"), StringLength(30)>
    Public Property AreaName() As String
    
    <DefaultSettingValue("1")>
    Public Property RecStatus() As Boolean
    

    End Class

    Public Class Occupation
    <Key, ScaffoldColumn(False)>
    Public Property OccupationID() As Integer

    Public Property OccupationName() As String
    

    End Class

    Public Class InvoiceHdr
    <Key, ScaffoldColumn(False)>
    Public Property InvoiceID() As Integer

    Public Property InvoiceNo() As String
    Public Property Amount() As Integer
    
    Public Property CustomerID As Integer
    

    End Clas

    Visual Studio 2015 & .NET 4.6 csharp database linq sales xml

  • Getting the Error Description from ModelState
    A ADSCNET

    I've done the following, created a model & then a function to be able to use it around my app:

    Public Function GetErrorList(ByVal modelState As ModelStateDictionary) As String
    Dim errorList = ( _
    From item In modelState _
    Where item.Value.Errors.Any() _
    Select item.Value.Errors(0).ErrorMessage).ToList()

        Return "Error in Rec. {0}: " & errorList.Item(0).ToString
    

    End Function

    Then I call the function:

    TryUpdateModel(Customer)
    If Not ModelState.IsValid Then
    ModelState.AddModelError("ModelError", String.Format(GetErrorList(ModelState), id))
    Return 0
    End If

    Visual Studio 2015 & .NET 4.6 help database question announcement

  • How to query database using Entity to SQL
    A ADSCNET

    Thanks a lot :)

    Visual Studio 2015 & .NET 4.6 database question linq sysadmin help

  • Getting the Error Description from ModelState
    A ADSCNET

    Hi, I'm using a FormView and update method which try to update the database, but it's throwing and error, I need to know on which field the error was but I am not able to extract the error msg from the ModelStateDictionary so I can know what is the exact error msg, the code as follow:

    Public Function UpdateTest(id As Integer) As Integer
    Dim Employee = _db.DbSet_Employees.Find(id)

        Try
    
            If Employee Is Nothing Then
                ModelState.AddModelError("ModelError", String.Format("Employee with ID {0} could not be found", id))
                Return 0
            End If
    
            TryUpdateModel(Employee)
            If Not ModelState.IsValid Then
                ModelState.AddModelError("ModelError", String.Format("Employee with ID {0} could not be updated", id))
    
                MsgBox(ModelState.GetErrorMessageForKey("error"))
    
                Return 0
            End If
    
        Catch ex As Exception
            ' Me.lblMsg.Text = Err.Description.ToString
            Me.lblMsg2.Text = ex.Message.ToString
            Return 0
        End Try
    
        ' write the changes to the database
        Return \_db.SaveChanges
    End Function
    

    Public Module ExtMethod
    <System.Runtime.CompilerServices.Extension> _
    Public Function GetErrorMessageForKey(ByVal dictionary As ModelStateDictionary, ByVal key As String) As String
    Return dictionary(key).Errors.First().ErrorMessage
    End Function
    End Module

    The problem start from TryUpdateModel then in the temperrory line MsgBox() Thanks for the help.

    Visual Studio 2015 & .NET 4.6 help database question announcement

  • How to query database using Entity to SQL
    A ADSCNET

    Great it works .. I just started with EF I used to use before for data access layer ado.net So this is LINQ to Entity OR Entity to SQL? as far as I know these are the only 2 data access methods to use in EF.

    Visual Studio 2015 & .NET 4.6 database question linq sysadmin help

  • How to query database using Entity to SQL
    A ADSCNET

    Richard thank you sooooo much for the time you are spending to answer my issues .. Now, regarding your code what I don't understand why you are putting if condition to check if the text box is empty or not? my problem is not with if the text is empty or not my problem is with the field in the database if the field is Null its a problem .. to follow your code, if the txtbox is not empty (which has some data to pass) and the field in the db is Null again it will return same false result.

    Visual Studio 2015 & .NET 4.6 database question linq sysadmin help

  • How to query database using Entity to SQL
    A ADSCNET

    I don't think this practical, what if FamilyName field is Null in the db ... correct? what do you think about what I said in my last post about replacing the Null.

    Visual Studio 2015 & .NET 4.6 database question linq sysadmin help

  • How to query database using Entity to SQL
    A ADSCNET

    After some testing, keeping the field default Null values is not practical, coz if in tele field entered number doesn't exist still it returns the record, say the field is Null and in txtMobile entered 7777888 it still returns the raw as found. But if replaced the Null with "" value it works fine, therefore I am wondering if there is a way around it or if it's (advisable or not) to not keep any Null as default value in all the db fields & replace it with "".

    Visual Studio 2015 & .NET 4.6 database question linq sysadmin help

  • How to query database using Entity to SQL
    A ADSCNET

    Excellent ... I didn't thought to solve it this way .. funny :) I was insisting to use the Coalesce. Thanks Richard.

    Visual Studio 2015 & .NET 4.6 database question linq sysadmin help

  • How to query database using Entity to SQL
    A ADSCNET

    It's the same query I used in my previous example, just added to it a telephone field where in the database most of the case is null.

    Visual Studio 2015 & .NET 4.6 database question linq sysadmin help

  • How to query database using Entity to SQL
    A ADSCNET

    Hi Richard, Any idea how to use COALESCE function to avoid the Null effect on the results, I can use the function with the sql query but the way you suggested as parameterized query not working with me .. sure I am missing somthing. Any suggestions? Thanks.

    Visual Studio 2015 & .NET 4.6 database question linq sysadmin help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups