Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,037

HOME > .NET Framework > Forum > มีปัญหามาถามครับ จากโค๊ดนี้มัน error ตรง Dim ds As DataSet = db.Query(qry)จากโค๊ดนี้นะครับ



 

มีปัญหามาถามครับ จากโค๊ดนี้มัน error ตรง Dim ds As DataSet = db.Query(qry)จากโค๊ดนี้นะครับ

 



Topic : 045064



โพสกระทู้ ( 3,750 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook



จากโค๊ดนี้มัน error ตรง Dim ds As DataSet = db.Query(qry)จากโค๊ดนี้นะครับ รบกวนช่วยดูให้หน่อยครับ
Private Shared Sub GetLocationDs(ByVal LocId As Integer)
        Dim db As New ConnectDb

        Dim sql As String = "Select top 1 * From Languages Where id=" & LocId
        Dim qry As New SqlQuery(sql)

        Dim ds As DataSet = db.Query(qry)
        Using ds
            If ds.Tables(0).Rows.Count > 0 Then
                Dim dr As DataRow = ds.Tables(0).Rows(0)
                Dim Loc As New Locations

                Loc.SetLocation(dr("ID"), dr("SubDomainName"), dr("WebsiteName"), dr("DefaultEmail"), dr("ContactEmail"), dr("Display"))
            End If
        End Using
    End Sub




Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-07-06 22:49:13 By : Dragons_first View : 1201 Reply : 6
 

 

No. 1



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


class ConnectDb กับ class SqlQuery ไม่ใช่ standard library

เอามาดูโค้ดเต็มๆ สิครับ






Date : 2010-07-06 22:56:01 By : tungman
 


 

No. 2



โพสกระทู้ ( 3,750 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

Imports Microsoft.VisualBasic
Imports System.Web.HttpContext
Imports System.Collections.Generic

Public Class Locations

    Public Const FolderFlag As String = Constants.FolderPhoto & "flags/"
    Shared HsGroupPage As Hashtable
    Shared HsGroupTier As Hashtable

    Shared ReadOnly Property HostName() As String
        Get
            Return MyFunc.Request.Url.Host.ToLower().Replace("www.", "")
        End Get
    End Property

    Shared ReadOnly Property IsLocallhost() As Boolean
        Get
            Return (HostName = "localhost")
        End Get
    End Property

    Shared ReadOnly Property GetLocationDefaultId() As Integer
        Get
            Return GetLocation(False, True)
        End Get
    End Property

    'Private Shared _LocationDefaultId As Integer
    'Shared Property LocationDefaultId() As Integer
    '    Get
    '        Return _LocationDefaultId 'GetLocation(False, True)
    '    End Get
    '    Set(ByVal value As Integer)
    '        _LocationDefaultId = value
    '    End Set
    'End Property


    Private Shared _NewLocationId As Integer()
    Shared Property NewLocationId() As Integer()
        Get
            Return _NewLocationId
        End Get
        Set(ByVal value As Integer())
            _NewLocationId = value
        End Set
    End Property

    '=[NUY]= so sorry my idea did mistake.
    'and Save As data in this file used this Property many and it should call from BaseMaster.LocationDefaultId
    'BaseMaster.LocationDefaultId has call when Admin.MasterPage Init, Need to call and get/set locationId and LocationDefaultId First.
    'LocationDefaultId used for check when Eng/Default site add new data and check for Save as record, that why I need to set on Init Master Page
    Shared ReadOnly Property LocationDefaultId() As Integer
        Get
            Return BaseMaster.LocationDefaultId
        End Get
    End Property

    ''' <summary>
    ''' For Check Location FrontEnd And BackEnd
    ''' </summary>
    ''' <returns>Location Id</returns>
    Public Shared Function GetId(Optional ByVal CanCheckDisplay As Boolean = False) As Integer
        If IsLocallhost() Then

            GetId = Sessions.AdminLocationId
            GetLocationDs(GetId)
        Else
            GetId = GetLocation(CanCheckDisplay)
        End If
    End Function

    Private Shared Sub GetLocationDs(ByVal LocId As Integer)
        Dim db As New ConnectDb

        Dim sql As String = "Select top 1 * From Languages Where id=" & LocId
        Dim qry As New SqlQuery(sql)

        Dim ds As DataSet = db.Query(qry)
        Using ds
            If ds.Tables(0).Rows.Count > 0 Then
                Dim dr As DataRow = ds.Tables(0).Rows(0)
                Dim Loc As New Locations

                Loc.SetLocation(dr("ID"), dr("SubDomainName"), dr("WebsiteName"), dr("DefaultEmail"), dr("ContactEmail"), dr("Display"))
            End If
        End Using
    End Sub

    Private Shared Function GetLocation(Optional ByVal CanCheckDisplay As Boolean = True, Optional ByVal IsDefaultOnly As Boolean = False) As Integer
        Dim LocationId As Integer = 0
        Dim SqlDisplay As String = IIf(CanCheckDisplay = True, " and (Display='1') ", "")
        Dim SqlCheckDomain As String = IIf(IsDefaultOnly = True, "", " or SubDomainName='" & HostName & "'")

        Dim db As New ConnectDb
        Dim sql As String = "Select top 1 * From Languages Where ( IsDefault='1' " & SqlCheckDomain & ")" & SqlDisplay & " order by IsDefault"
        Dim qry As New SqlQuery(sql)
        '  db.SetWhereParam(qry, "domain", HostName)

        Dim ds As DataSet = db.Query(qry)///บรรทัดนี้นะครับ
        Using ds
            If ds.Tables(0).Rows.Count > 0 Then
                Dim dr As DataRow = ds.Tables(0).Rows(0)
                Dim Loc As New Locations
                LocationId = dr("ID")
                Loc.SetLocation(dr("ID"), dr("SubDomainName"), dr("WebsiteName"), dr("DefaultEmail"), dr("ContactEmail"), dr("Display"))

                ' MyFunc.Response.Write("location: " & LocationId)
            Else
                LocationId = 1
            End If
        End Using

        Return LocationId
    End Function

    Private Shared PageChecngeLocation As String = Constants.FolderAdmin & "ClickDomain.aspx?backUrl=" & MyFunc.Server.UrlEncode(MyFunc.Request.RawUrl.ToString.ToLower) & "&LocationId="
    Public Shared Function GetLocationFlag(ByVal CurrLocation As Integer) As String
        Dim Str As New StringBuilder
        Dim Css As String = ""

        Dim cls As New MyDbObject("Languages")
        If cls.QueryWhereFlag("Id,FlagImage,SubdomainName", "id>0") Then
            Dim ds As DataTable = cls.GetDataSource.Tables(0)
            For Each Dr As DataRow In ds.Rows
                With Str
                    Css = ""
                    If CStr(CurrLocation) = CStr(Dr("id")) Then
                        Css = "flag_focus"
                    End If
                    .AppendLine(Builder.HTMLImageLink(MyFunc.ResolveUrl(Locations.FolderFlag) & Dr("FlagImage").ToString(), MyFunc.ResolveUrl(PageChecngeLocation) & Dr("id"), Dr("SubdomainName"), Css))
                    .AppendLine(" ")
                End With
            Next
        End If

        Return Str.ToString()
    End Function

    '=======================================================================
    Public Shared Function SaveAsDataByLanguage(ByVal NewLangId As Integer) As Boolean
        BrakeFunction()

        Return SaveAsDataByLanguage(New Integer() {NewLangId})
    End Function

    Public Shared Function SaveAsDataByLanguage(ByVal NewLangId As Integer()) As Boolean
        BrakeFunction()

        'Dim db As New ConnectDb
        'Dim conn As IDbConnection = db.GetConnection
        'Dim tx As IDbTransaction = Nothing
        Dim Loc As New Locations

        '== Please Use Tx
        _NewLocationId = NewLangId
        Loc.SaveAsGroupPage()
        Loc.SaveAsGroupTier()
        Loc.SaveAsFooter()

        Return True
    End Function

    Public Sub SaveAsGroupPage(Optional ByVal Ids As Integer = 0)
        BrakeFunction()

        Dim NewIds As Integer = 0
        Dim Tables As String = "GroupPage"
        Dim SqlOneRecord As String = ""
        If MyFunc.CheckIntValue(Ids) Then SqlOneRecord = " and id =" & Ids

        Dim Cls As New MyDbObject(Tables)
        If Cls.QueryWhereFlag("id", "LocationId={0}" & SqlOneRecord, LocationDefaultId) Then
            HsGroupPage = New Hashtable
            ' Dim _GroupPage As MapGroupPageId

            If NewLocationId.Length > 0 Then
                For Each xId As Integer In NewLocationId

                    If Not MyFunc.CheckIntValue(xId) Then Continue For
                    '========================================

                    For Each dr As DataRow In Cls.GetDataSource.Tables(0).Rows
                        Dim FieldStr As String = "LocationId{0}" & xId & "{1}RefEngId{0}" & dr("ID")
                        FieldStr = String.Format(FieldStr, Builder.SaveAsPipeSign, Builder.SaveAsCommaSign)
                        NewIds = Builder.SaveAsDs(Tables, dr("ID"), FieldStr)

                        HsGroupPage.Add(dr("ID"), NewIds)
                    Next
                Next
            End If
        End If
    End Sub

    Public Sub SaveAsGroupTier(Optional ByVal Ids As Integer = 0)
        BrakeFunction()

        Dim NewIds As Integer = 0
        Dim Tables As String = "GroupTier"
        Dim SourceImage, TempImage As String

        Dim TierFn As New TierConst
        TierFn.Table = Tables

        Dim SqlOneRecord As String = ""
        If MyFunc.CheckIntValue(Ids) Then SqlOneRecord = " and id =" & Ids

        Dim Cls As New MyDbObject(Tables)
        If Cls.QueryWhereFlag("id,ImageName", "LocationId={0}" & SqlOneRecord, LocationDefaultId) Then

            If NewLocationId.Length > 0 Then
                For Each xId As Integer In NewLocationId
                    HsGroupTier = New Hashtable

                    If Not MyFunc.CheckIntValue(xId) Then Continue For
                    '========================================

                    For Each dr As DataRow In Cls.GetDataSource.Tables(0).Rows
                        Dim FieldStr As String = "LocationId{0}" & xId & _
                                                 "{1}TotalOpen{0}0" & _
                                                 "{1}ImageName{0}" & _
                                                 "{1}RefEngId{0}" & dr("ID")
                        FieldStr = String.Format(FieldStr, Builder.SaveAsPipeSign, Builder.SaveAsCommaSign)
                        NewIds = Builder.SaveAsDs(Tables, dr("ID"), FieldStr)

                        HsGroupTier.Add(dr("ID"), NewIds)

                        '-- Save as Image from Row Source to Row destination 
                        SourceImage = "" : TempImage = ""
                        If Not MyFunc.CheckDataNull(dr("ImageName")) Then

                            TempImage = Replace(dr("ImageName"), dr("id"), NewIds)
                            Cls.SetValue("ImageName", TempImage)

                            SourceImage = TierFn.folderPathImage() & dr("ImageName")
                            TempImage = TierFn.folderPathImage() & TempImage
                            Builder.SaveAsImg(SourceImage, TempImage)

                            Cls.Update(NewIds)
                        End If

                        SaveAsSlidePhoto(TierTable.GroupTier, dr("ID"), NewIds)
                        SaveAsFilePdf(TierTable.GroupTier, dr("ID"), NewIds)
                        SaveAsTier(dr("ID"), NewIds)
                    Next

                Next
            End If

            SaveAsGroupPageSelected()

        End If

    End Sub

    Public Sub SaveAsGroupPageSelected()
        BrakeFunction()

        Dim Tables As String = "GroupPageSelect"
        Dim KeyStr As Integer
        Dim GpValue As Integer

        If Not (HsGroupPage.Count > 0 AndAlso HsGroupTier.Count > 0) Then Exit Sub
        For Each en As Integer In HsGroupPage.Keys
            KeyStr = en : GpValue = HsGroupPage.Item(en)

            Dim GpDs As New MyDbObject(Tables)
            Dim TierIds As Integer = 0

            '= Old GroupPageId = KeyStr (HsGroupPage.Keys) , Old TierID = dr("TierID")
            '= New GroupTierId = ValueStr (HsGroupPage.value) , New TierID = TierIds (HsGroupTier.value)

            If GpDs.QueryWhereFlag("id,GroupPageID,TierID", "GroupPageID={0}", KeyStr) Then
                For Each Gpdr As DataRow In GpDs.GetDataSource.Tables(0).Rows
                    TierIds = HsGroupTier.Item(CInt(Gpdr("TierID").ToString()))
                    If MyFunc.CheckIntValue(GpValue) AndAlso MyFunc.CheckIntValue(TierIds) Then
                        GpDs.SetValue("GroupPageID", GpValue)
                        GpDs.SetValue("TierID", TierIds)
                        'MyFunc.Response.Write(Ix & " | old : Gp " & KeyStr & " - Gt " & Gpdr("TierID") & " || New : Gp " & ValueStr & " - Gt " & TierIds & "<br />")
                        GpDs.Insert()
                    End If
                Next
            End If

        Next

        HsGroupPage = Nothing
        HsGroupTier = Nothing

    End Sub

    '=== save when add new tier (1 record)
    Public Sub SaveAsTier(ByVal Ids As Integer)
        BrakeFunction()

        If MyFunc.CheckIntValue(Ids) Then SaveAsTier(0, 0, Ids)
    End Sub

    '=== save when add new Langauge (1 record)
    Public Sub SaveAsTier(ByVal OldGtId As Integer, ByVal NewGtId As Integer, Optional ByVal Ids As Integer = 0)
        BrakeFunction()

        If (Not MyFunc.CheckIntValue(OldGtId) OrElse Not MyFunc.CheckIntValue(OldGtId)) AndAlso Not MyFunc.CheckIntValue(Ids) Then Exit Sub
        '========================================

        Dim NewIds As Integer = 0
        Dim Tables As String = "Tier"
        Dim SourceImage, TempImage As String

        Dim TierFn As New TierConst
        TierFn.Table = Tables

        Dim SqlOneRecord As String = "GroupTierId=" & OldGtId
        If MyFunc.CheckIntValue(Ids) Then SqlOneRecord = "id =" & Ids

        Dim Cls As New MyDbObject(Tables)
        If Cls.QueryWhereFlag("id,ImageName", SqlOneRecord) Then
            For Each dr As DataRow In Cls.GetDataSource.Tables(0).Rows

                Dim FieldStr As String = "GroupTierId{0}" & NewGtId & _
                                         "{1}TotalOpen{0}0" & _
                                         "{1}ImageName{0}" & _
                                         "{1}RefEngId{0}" & dr("ID")
                FieldStr = String.Format(FieldStr, Builder.SaveAsPipeSign, Builder.SaveAsCommaSign)
                NewIds = Builder.SaveAsDs(Tables, dr("ID"), FieldStr)

                '-- Save as Image from Row Source to Row destination 
                SourceImage = "" : TempImage = ""
                If Not MyFunc.CheckDataNull(dr("ImageName")) Then
                    TempImage = Replace(dr("ImageName"), dr("id"), NewIds)
                    Cls.SetValue("ImageName", TempImage)

                    SourceImage = TierFn.folderPathImage() & dr("ImageName")
                    TempImage = TierFn.folderPathImage() & TempImage
                    Builder.SaveAsImg(SourceImage, TempImage)

                    Cls.Update(NewIds)
                End If

                SaveAsSlidePhoto(TierTable.Tier, dr("ID"), NewIds)
                SaveAsFilePdf(TierTable.Tier, dr("ID"), NewIds)
            Next
        End If

    End Sub

    Public Function GetTierTableEnum(ByVal TbStr As String) As TierTable
        Select Case TbStr.ToLower
            Case "grouppage" : Return TierTable.GroupPage
            Case "grouptier" : Return TierTable.GroupTier
            Case "tier" : Return TierTable.Tier
            Case Else : Return 0
        End Select
    End Function

    Public Enum TierTable
        GroupPage
        GroupTier
        Tier
    End Enum

    Public Shared Sub BrakeFunction()
        Exit Sub
    End Sub

    '=== save when add Slide Photo (1 record)
    Public Sub SaveAsSlidePhoto(ByVal OtherTierId As Integer(), ByVal Ids As Integer)
        BrakeFunction()

        If MyFunc.CheckIntValue(Ids) Then SaveAsSlidePhoto(0, 0, OtherTierId, Ids)
    End Sub

    '=== save when add new Langauge (1 record)
    Public Sub SaveAsSlidePhoto(ByVal Table As TierTable, ByVal OldDataId As Integer, ByVal NewDataId As String)
        BrakeFunction()

        SaveAsSlidePhoto(Table, OldDataId, New Integer() {NewDataId})
    End Sub

    Public Sub SaveAsSlidePhoto(ByVal Table As TierTable, ByVal OldDataId As Integer, ByVal NewDataId As Integer(), Optional ByVal Ids As Integer = 0)
        BrakeFunction()

        If (Not MyFunc.CheckIntValue(OldDataId) OrElse NewDataId.Length = 0) AndAlso Not MyFunc.CheckIntValue(Ids) Then Exit Sub
        '========================================

        Dim NewIds As Integer = 0
        Dim Tables As String = "SlidePhoto"
        Dim SourceImage, TempImage As String
        Dim TierFn As New TierConst
        TierFn.Table = Table.ToString()

        Dim SqlOneRecord As String = String.Format("MainTable='{0}' and MainId={1}", Table.ToString(), OldDataId)
        If MyFunc.CheckIntValue(Ids) Then SqlOneRecord = "id =" & Ids

        Dim Cls As New MyDbObject(Tables)
        If Cls.QueryWhereFlag("id,ImageName", SqlOneRecord) Then

            If NewDataId.Length > 0 Then
                For Each xId As Integer In NewDataId

                    If Not MyFunc.CheckIntValue(xId) Then Continue For
                    '========================================

                    For Each dr As DataRow In Cls.GetDataSource.Tables(0).Rows
                        Dim FieldStr As String = "MainId{0}" & xId
                        FieldStr = String.Format(FieldStr, Builder.SaveAsPipeSign, Builder.SaveAsCommaSign)
                        NewIds = Builder.SaveAsDs(Tables, dr("ID"), FieldStr)

                        '-- Save as Image from Row Source to Row destination 
                        SourceImage = "" : TempImage = ""
                        If Not MyFunc.CheckDataNull(dr("ImageName")) Then

                            SourceImage = TierFn.folderPathSlidePhoto() & dr("ImageName")
                            Dim Ext As String = Path.GetExtension(SourceImage)
                            TempImage = NewIds & "_" & Now.ToString("MMddyyyy") & Ext
                            Cls.SetValue("ImageName", TempImage)

                            TempImage = TierFn.folderPathSlidePhoto() & TempImage
                            Builder.SaveAsImg(SourceImage, TempImage)

                            Cls.Update(NewIds)
                        End If
                    Next

                Next
            End If

        End If
    End Sub


    '=== save when add Slide Photo (1 record)
    Public Sub SaveAsFilePdf(ByVal OtherTierId As Integer(), ByVal Ids As Integer)
        BrakeFunction()

        If MyFunc.CheckIntValue(Ids) Then SaveAsFilePdf(0, 0, OtherTierId, Ids)
    End Sub

    '=== save when add new Langauge (1 record)
    Public Sub SaveAsFilePdf(ByVal Table As TierTable, ByVal OldDataId As Integer, ByVal NewDataId As String)
        BrakeFunction()

        SaveAsFilePdf(Table, OldDataId, New Integer() {NewDataId})
    End Sub

    Public Sub SaveAsFilePdf(ByVal Table As TierTable, ByVal OldDataId As Integer, ByVal NewDataId As Integer(), Optional ByVal Ids As Integer = 0)
        BrakeFunction()

        If (Not MyFunc.CheckIntValue(OldDataId) OrElse NewDataId.Length = 0) AndAlso Not MyFunc.CheckIntValue(Ids) Then Exit Sub
        '========================================

        Dim NewIds As Integer = 0
        Dim Tables As String = "FilePdf"
        Dim SourceImage, TempImage As String

        Dim TierFn As New TierConst
        TierFn.Table = Table.ToString()

        Dim SqlOneRecord As String = String.Format("Tables='{0}' and Ids={1}", Table.ToString(), OldDataId)
        If MyFunc.CheckIntValue(Ids) Then SqlOneRecord = "id =" & Ids

        Dim Cls As New MyDbObject(Tables)
        If Cls.QueryWhereFlag("id,FileName", SqlOneRecord) Then
            If NewDataId.Length > 0 Then
                For Each xId As Integer In NewDataId

                    If Not MyFunc.CheckIntValue(xId) Then Continue For
                    '========================================

                    For Each dr As DataRow In Cls.GetDataSource.Tables(0).Rows
                        Dim FieldStr As String = "Ids{0}" & xId
                        FieldStr = String.Format(FieldStr, Builder.SaveAsPipeSign, Builder.SaveAsCommaSign)
                        NewIds = Builder.SaveAsDs(Tables, dr("ID"), FieldStr)

                        '-- Save as Image from Row Source to Row destination 
                        SourceImage = "" : TempImage = ""
                        If Not MyFunc.CheckDataNull(dr("FileName")) Then

                            TempImage = Replace(dr("FileName"), 1000 + dr("id"), 1000 + NewIds)
                            Cls.SetValue("FileName", TempImage)

                            SourceImage = Constants.FolderFnPDF & dr("FileName")
                            TempImage = Constants.FolderFnPDF & TempImage
                            Builder.SaveAsImg(SourceImage, TempImage)

                            Cls.Update(NewIds)
                        End If
                    Next

                Next
            End If
        End If
    End Sub

    Private Sub SaveAsFooter()
        BrakeFunction()

        Dim Tables As String = "Footer"

        Dim Cls As New MyDbObject(Tables)
        If Cls.QueryWhereFlag("id", "LocationId={0}", LocationDefaultId) Then
            If NewLocationId.Length > 0 Then
                For Each xId As Integer In NewLocationId
                    Builder.SaveAsDs(Tables, Cls.GetValue("ID"), "LocationId" & Builder.SaveAsPipeSign & xId)
                Next
            End If
        End If
    End Sub

    ''' <summary>
    ''' Get Other Languages Record Is Reference With Default Language for save as data
    ''' </summary>
    Public Function DsFromOtherLocation(ByVal tables As TierTable, ByVal RefEngId As Integer) As Integer()
        BrakeFunction()

        Dim ArrId As Integer() = {}

        If Not MyFunc.CheckIntValue(RefEngId) Then Return ArrId
        '========================================

        Dim cls As New MyDbObject(tables.ToString())
        If cls.QueryWhereFlag("id,refEngId", "refEngId={0}", RefEngId) Then
            Dim dt As DataTable = cls.GetDataSource.Tables(0)
            Dim iLoop As Integer = 0
            ReDim ArrId(dt.Rows.Count)
            For Each dr As DataRow In dt.Rows
                ArrId.SetValue(dr("id"), iLoop)
                iLoop = iLoop + 1
            Next
        End If
        Return ArrId
    End Function

    ''' <summary>
    ''' Get Other Languages Record Is Reference With Default Language for save as data
    ''' </summary>
    Public Function GetIDOtherLocation() As Integer()
        Dim ArrId As Integer() = {}
        Dim cls As New MyDbObject("languages")
        If cls.QueryWhereFlag("id", "id <>" & LocationDefaultId) Then
            Dim dt As DataTable = cls.GetDataSource.Tables(0)
            Dim iLoop As Integer = 0
            ReDim ArrId(dt.Rows.Count)
            For Each dr As DataRow In dt.Rows
                ArrId.SetValue(dr("id"), iLoop)
                iLoop = iLoop + 1
            Next
        End If
        Return ArrId
    End Function


    '===================================================
    '=[NUY]= So sorry if my coding haven't responsibility. I try to used some method. ^^
    Private _Id As Integer
    Public Shared _SubDoaminName As String
    Shared _WebsiteName As String
    Private _InfoEmail As String
    Private _ContactEmail As String
    Private _Display As Boolean

    Private Sub SetLocation(ByVal id As Integer, ByVal SubDoaminName As String, ByVal WebsiteName As String, _
                             ByVal InfoEmail As String, ByVal ContactEmail As String, ByVal Display As String)
        _Id = id
        _SubDoaminName = SubDoaminName
        _WebsiteName = WebsiteName
        _InfoEmail = InfoEmail
        _ContactEmail = ContactEmail
        _Display = (Display = "1")
    End Sub

    ''' <summary>
    ''' Get Website Information 
    ''' </summary>
    ''' <param name="DomainName">HttpContext.Current.Request.Url.Host</param>
    ''' <param name="isFontsite">Front site or Back Office</param>
    Public Shared Function GetDTSiteByDomain(ByVal DomainName As String, _
                                             Optional ByVal isFontsite As Boolean = False) As DataTable
        GetDTSiteByDomain = Nothing
        Dim db As New ConnectDb

        '== Get Default fields must to required ==
        Dim RequireField As String = ""
        RequireField += " Id, WebsiteName, SubDomainName, ISNULL(CultureCode,'') as CultureCode "
        RequireField += " ,DefaultEmail As FromEmail, ContactEmail As ToEmail "

        Dim DBTable As String = " FROM Languages "
        Dim qry As SqlQuery
        Dim UserLocateId As String = Locations.GetId(isFontsite)

        If (Current.Request.Url.Host = "localhost") OrElse Not isFontsite Then
            Dim SQL As String = " SELECT " & RequireField & DBTable & " WHERE (Id=" & UserLocateId & ")"
            qry = New SqlQuery(SQL)
        Else
            Dim SplitDomainName As String() = Split(DomainName, ".")
            If SplitDomainName.Length > 3 Then
                DomainName = SplitDomainName(1) & "." & SplitDomainName(2) & "." & SplitDomainName(3)
            End If

            Dim SQL As String = ""
            SQL = " SELECT * FROM ( "
            SQL &= "SELECT   " & RequireField & DBTable & " WHERE  (SubDomainName = @domain AND Display='1') "
            SQL &= " UNION ALL SELECT " & RequireField & DBTable & " WHERE  (IsDefault='1') "
            SQL &= " ) Site "
            qry = New SqlQuery(SQL)
            db.SetWhereParam(qry, "domain", DomainName)
        End If

        Dim dt As DataTable = db.Query(qry).Tables(0)
        If dt.Rows.Count > 0 Then
            GetDTSiteByDomain = dt
        End If
    End Function

    ''' <summary>
    ''' Set Culture Code For Receive Fix Text From Global Resource File By Culture Code
    ''' </summary>
    ''' <param name="Pages">Page of Master Page</param>
    ''' <param name="CultureCodeName">Culture Code</param>
    Public Shared Sub SetCultureInfo(ByVal Pages As Page, _
                                     Optional ByVal CultureCodeName As String = "en-US")
        Dim cl As New System.Globalization.CultureInfo(CultureCodeName)
        System.Threading.Thread.CurrentThread.CurrentUICulture = cl
        Pages.DataBind()
    End Sub

    ''' <summary>
    ''' Display Flag on Website
    ''' </summary>
    ''' <param name="SiteId">website id</param>
    ''' <param name="IsFrontEnd">front end or back end</param>
    ''' <param name="IsDisplayFlag">display or hide flag</param>
    ''' <param name="PageDefault">index.aspx</param>
    Public Shared Function ListFlag(ByVal SiteId As Integer, _
                            Optional ByVal IsFrontEnd As Boolean = True, _
                            Optional ByVal IsDisplayFlag As Boolean = True, _
                            Optional ByVal PageDefault As String = "index.aspx") As String
        Dim HTMLFlag As String = ""
        Dim StrConditionSQL As String = IIf(IsFrontEnd = True, " WHERE (Display='1') ", "")

        If IsDisplayFlag Then
            Dim db As New ConnectDb
            Dim sb As New StringBuilder
            Dim sql As String = ""
            sql &= "SELECT Id,SubDomainName as DomainName,"
            sql &= "WebsiteName,SetOrder,ISNULL(FlagImage,'') as FlagImage "
            sql &= "From Languages "
            sql &= StrConditionSQL
            sql &= "Order By SetOrder "

            Dim qry As New SqlQuery(sql)
            Dim ds As DataSet = db.Query(qry)
            Dim StrFullDomain As String = ""

            If ds.Tables(0).Rows.Count > 0 Then
                Dim pageBackLink As String = ""
                Dim LinkFlag As String = ""
                Dim CssCurrent As String = ""
                Dim RootLinkLocal As String = IIf(IsFrontEnd = True, Constants.RootPath, Constants.FolderAdmin)

                For Each dr As DataRow In ds.Tables(0).Rows
                    If (HttpContext.Current.Request.Url.Host = "localhost") Then
                        pageBackLink = MyFunc.ResolveUrl(RootLinkLocal & "clickdomain.aspx?locationid=" & dr("ID"))
                    Else
                        Dim StrSubDomain As String = ""
                        Dim StrDomainName As String = dr("DomainName")
                        Dim SplitDomainName As String() = Split(StrDomainName, ".")
                        If SplitDomainName.Length = 2 Then 'medico-services.com
                            StrSubDomain = "www."
                        End If

                        StrFullDomain = String.Format("http://{0}{1}", StrSubDomain, StrDomainName)
                        pageBackLink = StrFullDomain & "/" & PageDefault
                    End If

                    Dim StrTitle As String = dr("WebsiteName")
                    Dim imgFlagPath As String = Locations.FolderFlag & dr("FlagImage")
                    CssCurrent = IIf(SiteId = dr("id"), "current", "")

                    sb.AppendLine(Builder.HTMLImageLink(imgFlagPath, pageBackLink, StrTitle, CssCurrent))
                    sb.AppendLine(" ")
                Next

                HTMLFlag = sb.ToString
            End If
        End If

        Return HTMLFlag
    End Function
End Class


ถ้าไงรบกวนด้วยนะครับ ขอบคุณครับ
Date : 2010-07-06 23:50:22 By : Dragons_first
 

 

No. 3



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


นี่มัน class location ยังมีอีก 2 class

เอา class ConnectDb กับ class SqlQuery มาด้วย

แล้วก็โพส error ไว้ด้วย
Date : 2010-07-07 08:28:14 By : tungman
 


 

No. 4



โพสกระทู้ ( 3,750 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

connectdb.vb ครับ
Public Class ConnectDb
    Inherits SqlDatabase

    Private Shared mMyDataBase As DatabaseInfo
    Public Overrides Property MyDatabase() As DatabaseInfo
        Get

            Dim dbInfo As DatabaseInfo = mMyDataBase
            If (dbInfo Is Nothing) Then
                dbInfo = New DatabaseInfo()
                dbInfo.ServerType = DatabaseType.SqlServer

                Dim serverName As String = HttpContext.Current.Request.ServerVariables("SERVER_NAME")
                If serverName = "localhost" OrElse serverName = "4b" Then
                    dbInfo.ServerName = "4b"
                    dbInfo.DatabaseName = "medico_services_com_medico"
                    dbInfo.UserName = "medico"
                    dbInfo.Password = "medico"
                Else
                    dbInfo.ServerName = "mssql0803\inst1"
                    dbInfo.DatabaseName = "382888_meservice"
                    dbInfo.UserName = "382888_meservice"
                    dbInfo.Password = "me3Vep+rvice"
                End If

                mMyDataBase = dbInfo
            End If
            Return mMyDataBase

        End Get
        Set(ByVal value As DatabaseInfo)
            mMyDataBase = value
        End Set
    End Property
End Class

Date : 2010-07-07 09:48:55 By : Dragons_first
 


 

No. 5



โพสกระทู้ ( 3,750 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

error ครับ
Server Error in '/' Application. 
--------------------------------------------------------------------------------

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Source Error: 

Line 99:         '  db.SetWhereParam(qry, "domain", HostName)Line 100:Line 101:        Dim ds As DataSet = db.Query(qry)Line 102:        Using dsLine 103:            If ds.Tables(0).Rows.Count > 0 Then
 

Source File: d:\WWWROOT\admin_smilehost\max-007.com\medico-services.com\www\App_Code\Languages\Location.vb    Line: 101 


Date : 2010-07-07 09:51:57 By : Dragons_first
 


 

No. 6



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


มันสร้าง connection กับ sql server ไม่ได้น่ะ ลองตรวจสอบ connection string ดูนะ

อีกอย่างนี่ถ้าไม่เจอ datarow หรือ stringbuilder นี่ไม่รู้เลยนะว่าใช้ framework ของ dotnet

ทำไมไม่ใช้ sqlclient ติดต่อกับ sql server ล่ะ ???
Date : 2010-07-07 10:05:24 By : tungman
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : มีปัญหามาถามครับ จากโค๊ดนี้มัน error ตรง Dim ds As DataSet = db.Query(qry)จากโค๊ดนี้นะครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่