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,027

HOME > .NET Framework > Forum > ถามเรื่อง Code ASP.NET คับบ ติด Error คับบ คือ Code ผมประมาณว่า sp:GridView



 

ถามเรื่อง Code ASP.NET คับบ ติด Error คับบ คือ Code ผมประมาณว่า sp:GridView

 



Topic : 024438



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



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




คือ Code ผมประมาณว่า
Code (VB.NET)
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
OnPageIndexChanging="ShowPageCommand" AllowPaging="True" ShowFooter="True" >
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<Columns>
<ItemTemplate>
<asp:TextBox ID="sale_num" runat="server" Text = "0"></asp:TextBox>
</ItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Buy" CommandName="Buy" ></asp:Button>
</ItemTemplate>
</Columns>
</asp:GridView>
' ------------------------------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack() Then
Dim StrConn As String = WebConfigurationManager.ConnectionStrings("conn").ConnectionString
Dim dt As New DataTable
Dim da1 As New System.Data.SqlClient.SqlDataAdapter("SELECT * FROM mode", StrConn)
da1.Fill(dt)
Dim LT As New ListItem
'LT.Text = "-- Select Mode --"
'LT.Value = ""
'mode.Items.Add(LT)

For i As Integer = 0 To dt.Rows.Count - 1
mode.Items.Add(New ListItem(dt.Rows(i).Item("mode"), dt.Rows(i).Item("id_mode")))
Next
End If
Gridbind()
End Sub

Sub Gridbind()
Dim strConn As String
Dim sqluername As String

strConn = WebConfigurationManager.ConnectionStrings("conn").ConnectionString

Dim Conn As New SqlConnection(strConn)
Conn.Open()

sqluername = "SELECT * FROM drug,mode WHERE mode.id_mode='" & mode.Text & "'AND mode.id_mode = drug.id_mode order by name_drug,lot_num "

Dim da As New SqlDataAdapter(sqluername, Conn)
Dim ds As New DataSet
da.Fill(ds, "drug")

GridView1.DataSource = ds.Tables("drug")
GridView1.DataBind()

End Sub

Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "Buy" Then
For Each gr As GridViewRow In Me.GridView1.Rows
If gr.RowType = DataControlRowType.DataRow Then

Dim tmpTextbox As TextBox = gr.Cells(5).FindControl("sale_num")

If tmpTextbox IsNot Nothing Then

Me.Session("aaaa") = tmpTextbox.Text
Response.Write(tmpTextbox.Text)

End If
End If
Next
End If
End Sub

คือพอคลิกปุ่ม Buy แล้ว Error เลยคับ ช่วยแนะนำทีว่าผิดตรงไหน ขอบคุณคับบบ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-01-30 23:40:00 By : hero_big View : 8455 Reply : 5
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

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

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

Error ว่าอะไรครับ หรือไม่ลองใช้ Tool Debug ดูก่อนน่ะครับ จะช่วยได้เยอะเลยครับ






Date : 2009-01-31 07:50:30 By : webmaster
 


 

No. 2



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



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


ตอนรันแล้ว คลิกปุ่ม มันจะฟ้อง Error ประมาณนี้ คับบบ

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.ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:


[ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +367
System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +83
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +51
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840




ช่วยแนะนำที ว่ามันผิดตรงไหน คับบบ ขอบคุรคับบบ
Date : 2009-02-01 23:05:17 By : hero_big
 

 

No. 3

Guest


ใน web.config แก้ tag pages ตามนี้ฮะ

<pages validateRequest="false" enableEventValidation="false">


https://www.thaicreate.com/dotnet/forum/039394.html
Date : 2009-02-05 13:05:44 By : stunt
 


 

No. 4

Guest


** รบกวนท่านผู้รู้ช่วยหน่อยครับ

ปัญหาคือ ผมนำเว็บไปใส่ในโน๊ตบุ๊คแล้วรันก็ปกติ แต่พอนำไปใส่ในเครื่องใหม่ก็รันไม่ได้แล้วขึ้นฟ้องอย่างนี้

Server Error in '/' Application.
Login failed for user 'SMART_PRINT\ASPNET'.
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: Login failed for user 'SMART_PRINT\ASPNET'.

Source Error:

Line 74: End With
Line 75: End If
Line 76: DBConnection.Open()
Line 77: End Sub
Line 78:


Source File: C:\Inetpub\wwwroot\Menaweb\App_Code\DBClass.vb Line: 76

Stack Trace:

[SqlException (0x80131904): Login failed for user 'SMART_PRINT\ASPNET'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844759
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +144
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
DBClass.OpenDB() in C:\Inetpub\wwwroot\Menaweb\App_Code\DBClass.vb:76
DBClass.GetDataReader(String sSQL) in C:\Inetpub\wwwroot\Menaweb\App_Code\DBClass.vb:171
login.query_gridview_hotnews() in C:\Inetpub\wwwroot\Menaweb\login.aspx.vb:56
login.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Menaweb\login.aspx.vb:13
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
Date : 2009-08-26 15:48:14 By : ody
 


 

No. 5

Guest


ตัวนี้เป็นโค๊ดของหน้าที่มันฟ้อง error

Option Explicit On '--ทำหน้าที่กำหนดว่าตัวแปรทุกตัวที่คุณใช้งานต้องมีการประกาศการใช้งานก่อนทุกครั้ง
Option Strict On '--ทำหน้าที่กำหนดว่าการเปลี่ยนแปลงข้อมูลทุกชนิดจะใช้กติกาอย่างเข้มงวดและเคร่งครัด
'Imports System.Management
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient

Public Class DBClass
Inherits System.Web.UI.Page
Private _ErrorStatus As String = Nothing '--เก็บค่า Error Message ในการ Connection Database--'
Private HostIP As String = Nothing '--เก็บค่า IP ของเครื่อง Host ที่เรียกใช้โปรแกรม

#Region "DBClass SQLServer"
Public Event onDBError(ByVal strError As String)
Public Event onSuccess(ByVal strMessage As String)
Private G_DBuser As String = "sa" '--เก็บค่า User Sqlserver
Private G_DBpassword As String = "" '--เก็บค่า Password Sqlserver
'--Connection SQL Server 2005---'
'Private G_STR_Connection As String = "Data Source=MNHHCIT903\SQL903;Initial Catalog=Mena_General;User ID=sa;Password=;"
'Private G_STR_Connection As String = "Data Source=Lee;Initial Catalog=Mena_General;User ID=" & G_DBuser & ";" & "Password=" & G_DBpassword & ";"
'---Private G_STR_Connection As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("webconn").ConnectionString
'
'
'--Connection SQL Server 2000---'
Private G_STR_Connection As String = "Data Source=192.2.3.107;Initial Catalog=Mena_General;User ID=sa;Password=;Max Pool Size=200;Enlist=true;"
'
'
Public strSql As String = "" '--เก็บค่า String เพื่อส่งไป Query
'
'
Private DBConnection As SqlConnection
Private DBCommand As SqlCommand
Private DBAdapter As SqlDataAdapter

Public Shared Sub OpenConnection()
'xxxx
End Sub

Public Sub New()
Try
DBConnection = New SqlConnection(G_STR_Connection)
Catch ex As Exception
G_STR_Connection = "Data Source=192.2.2.199;Initial Catalog=Mena_General;User ID=sa;Password=;Enlist=false;"
DBConnection = New SqlConnection(G_STR_Connection)
End Try
DBCommand = New SqlCommand
DBCommand.Connection = DBConnection
DBAdapter = New SqlDataAdapter
End Sub

Public Sub New(ByVal con_close As Boolean)
'Do Nothing Cause Not open Connection
'เวลาเรียกใช้ ให้ Private WithEvents myDB As New DBClass(False)
End Sub

Public Sub New(ByVal DBname As String)
'---DB = New DBClass("Mena_Center") '--เริ่มเรียกใช้ Database
'If DBname.Length <> 0 Then
'DBConnection = New SqlConnection(G_STR_Connection & ";Initial Catalog=" & DBname)
'Else
'DBConnection = New SqlConnection(G_STR_Connection & ";Initial Catalog=Mena_Center")
'End If
DBCommand = New SqlCommand
DBCommand.Connection = DBConnection
DBAdapter = New SqlDataAdapter
End Sub

Private Sub OpenDB() ' Optional ByVal DBname As String = "") '--Close แล้ว Open connect datablase
_ErrorStatus = Nothing
If DBConnection IsNot Nothing Then
With DBConnection
.Close()
'.Dispose() '--คืนทรัพยากรในกับระบบ
End With
End If
DBConnection.Open()
End Sub

Public Sub CloseDB() '--Close connect datablase
DBConnection.Close()
Call ShowError()
End Sub

Private Sub Initial_DataBase(Optional ByVal DATABASE_Name As String = "Mena_center")
If Left(DATABASE_Name.ToUpper, 4) = "MENA" Then
G_STR_Connection = "Data Source=192.2.2.199;Initial Catalog=" & DATABASE_Name & ";User ID=sa;Password=;Enlist=false;"
Else
Select Case Left(DATABASE_Name.ToUpper, 5)
Case "CT"
G_STR_Connection = "Data Source=192.2.2.199;Initial Catalog=Mena_Center;User ID=sa;Password=;Enlist=false;"
Case "HR"
G_STR_Connection = "Data Source=192.2.2.199;Initial Catalog=Mena_HR;User ID=sa;Password=;Enlist=false;"
Case "OF"
G_STR_Connection = "Data Source=192.2.2.199;Initial Catalog=Mena_Office;User ID=sa;Password=;Enlist=false;"
Case "LE"
G_STR_Connection = "Data Source=192.2.2.199;Initial Catalog=Mena_Leasing;User ID=sa;Password=;Enlist=false;"
Case Else
If Right(Left(DATABASE_Name.ToUpper, 6), 3) = "GEN" Then
G_STR_Connection = "Data Source=192.2.2.199;Initial Catalog=Mena_General;User ID=sa;Password=;Enlist=false;"
Else
G_STR_Connection = "Data Source=192.2.2.199;Initial Catalog=Mena_Center;User ID=sa;Password=;Enlist=false;"
End If
End Select
End If
End Sub

Public Function GetDataSet(ByVal sSQL As String) As DataSet
Dim GDS As New DataSet
Try
Call OpenDB()
DBCommand.CommandText = sSQL
DBCommand.CommandTimeout = 6000 '-- Utian coding
DBAdapter.SelectCommand = DBCommand
DBAdapter.Fill(GDS)
Catch Ex As Exception
_ErrorStatus = "<Error Or Problem> พบปัญหาในการติดต่อฐานข้อมูล (GetDataSet)" & vbCr & vbCr & Ex.Message
'RaiseEvent onDBError(_ErrorStatus)
Finally
Call CloseDB()
End Try
Return GDS
End Function

Public Function GetSPDataSet(ByVal sSQL As String, Optional ByVal para As String = "", Optional ByVal DBname As String = "") As DataSet
Dim GDS As New DataSet
Dim arrStr() As String
'
'--เวลาใช้--'
'Ds = DB.GetSPDataSet("SP_ValidateUser", "@uname;M-240;@upassword;3361", "Mena_HR")
'จะได้
'.CommandText = sSQL
'.Parameters.Add(New SqlParameter("@uname", "M-240"))
'.Parameters.Add(New SqlParameter("@upassword", "3361"))
'
'หรือ แบบ 2 None parameter
'Ds = DB.GetSPDataSet("SP_GetDatetime","","Mena_Center")
'
'
If DBname.Length <> 0 Then
Call Initial_DataBase(DBname)
Else
Call Initial_DataBase(sSQL)
End If
DBConnection = New SqlConnection(G_STR_Connection)
Call OpenDB()
Try
With DBCommand
.CommandText = sSQL '---Stored Procedure to Call
If para <> "" Then
arrStr = Split(para, ";")
For i As Integer = 0 To arrStr.Length - 1 Step +2
.Parameters.Add(New SqlParameter(arrStr(i), arrStr(i + 1)))
Next
End If
.CommandTimeout = 6000 '-- Utian coding
.CommandType = CommandType.StoredProcedure '---Setup Command Type
.Connection = DBConnection
End With
DBAdapter.SelectCommand = DBCommand
DBAdapter.Fill(GDS)
Catch Ex As Exception
_ErrorStatus = "<Error Or Problem> พบปัญหาในการติดต่อฐานข้อมูล (GetSPDataSet)" & vbCr & vbCr & Ex.Message
Finally
Call CloseDB()
End Try
Return GDS
End Function

Public Function GetDataReader(ByVal sSQL As String) As SqlDataReader
Dim Gdr As SqlDataReader = Nothing
Call OpenDB()
Try
DBCommand = New SqlCommand(sSQL, DBConnection)
DBCommand.CommandTimeout = 6000 '-- Utian coding
Gdr = DBCommand.ExecuteReader()
Catch ex As Exception
_ErrorStatus = "<Error Or Problem> พบปัญหาในการติดต่อฐานข้อมูล (GetSPDataReader)" & vbCr & vbCr & ex.Message
End Try
'If Gdr.HasRows Then
' While Gdr.Read()
' MsgBox(Gdr(0).ToString())
' End While
'End If
'เมื่อ Return Gdr จะถูกปิดโดยอัตโนมัต ตัวแปลในระดับ Block
'fload.Close()
'fload.Dispose() '--มีหน้าที่คืน Unmanaged resource ทันที
Return Gdr
End Function

Public Function GetSPDataReader(ByVal sSQL As String, Optional ByVal para As String = "", Optional ByVal DBname As String = "") As SqlDataReader
Dim Gdr As SqlDataReader = Nothing
Dim arrStr() As String

If DBname.Length <> 0 Then
Call Initial_DataBase(DBname)
Else
Call Initial_DataBase(sSQL)
End If
DBConnection = New SqlConnection(G_STR_Connection)
Call OpenDB()
Try
With DBCommand
.CommandText = sSQL '---Stored Procedure to Call
If para <> "" Then
arrStr = Split(para, ";")
For i As Integer = 0 To arrStr.Length - 1 Step +2
.Parameters.Add(New SqlParameter(arrStr(i), arrStr(i + 1)))
Next
End If
.CommandTimeout = 6000 '-- Utian coding
.CommandType = CommandType.StoredProcedure '---Setup Command Type
.Connection = DBConnection
End With
Gdr = DBCommand.ExecuteReader()
Catch ex As Exception
_ErrorStatus = "<Error Or Problem> พบปัญหาในการติดต่อฐานข้อมูล (GetDataReader)" & vbCr & vbCr & ex.Message
End Try
Return Gdr
End Function

Public Function GetDataTable(ByVal sSQL As String) As DataTable
Dim GDT As New DataTable
Try
Call OpenDB()
DBCommand.CommandText = sSQL
DBCommand.CommandTimeout = 6000 '-- Utian coding
DBAdapter.SelectCommand = DBCommand
DBAdapter.Fill(GDT)
Catch Ex As Exception
_ErrorStatus = "<Error Or Problem> พบปัญหาในการติดต่อฐานข้อมูล (GetDataTable)" & vbCr & vbCr & Ex.Message
Finally
Call CloseDB()
End Try
Return GDT
End Function

Public Function GetSPDataTable(ByVal sSQL As String, Optional ByVal para As String = "", Optional ByVal DBname As String = "") As DataTable
Dim GDT As New DataTable
Dim arrStr() As String
If DBname.Length <> 0 Then
Call Initial_DataBase(DBname)
Else
Call Initial_DataBase(sSQL)
End If
DBCommand.Connection = DBConnection
Call OpenDB()
Try
With DBCommand
.CommandText = sSQL '---Stored Procedure to Call
If para <> "" Then
arrStr = Split(para, ";")
For i As Integer = 0 To arrStr.Length - 1 Step +2
.Parameters.Add(New SqlParameter(arrStr(i), arrStr(i + 1)))
Next
End If
.CommandTimeout = 6000 '-- Utian coding
.CommandType = CommandType.StoredProcedure '---Setup Command Type
.Connection = DBConnection
End With
DBAdapter.SelectCommand = DBCommand
DBAdapter.Fill(GDT)
Catch Ex As Exception
_ErrorStatus = "<Error Or Problem> พบปัญหาในการติดต่อฐานข้อมูล (GetSPDataTable)" & vbCr & vbCr & Ex.Message
Finally
Call CloseDB()
End Try
Return GDT
End Function

Public Function Execute(ByVal sSQL As String) As Boolean
'--วิธีเรียกใช้
'
'strSql = "Insert Into Mena_Center..XXX (CUS_CODE)values ('99')
'If DB.Execute(strSql) = True Then
' MB.DispSaveNewData()
' False มี Error
'End If
Dim Execute_Completes As Boolean = False
Try
Call OpenDB()
DBCommand.CommandText = sSQL
DBCommand.CommandTimeout = 6000 '-- Utian coding
DBCommand.ExecuteNonQuery()
RaiseEvent onSuccess("<Save Data Completes> บันทึกข้อมูล เรียบร้อย") '--Execute Success
Execute_Completes = True
Catch Ex As Exception
_ErrorStatus = "<Error Or Problem> พบปัญหาในการบันทึกข้อมูลลงฐานข้อมูล/หรือรหัสซ้ำ (Execute) " & vbCr & vbCr & Ex.Message
Execute_Completes = False
Finally
Call CloseDB()
End Try
Return Execute_Completes
End Function

Public Sub ExecuteStoredProc(ByVal sSQL As String)
'--Run a stored procedure that does not return records
Dim lngRecords As Integer = 0
Try
Call OpenDB()
DBCommand.CommandText = sSQL
DBCommand.CommandTimeout = 6000 '-- Utian coding
DBCommand.CommandType = CommandType.StoredProcedure
DBCommand.ExecuteNonQuery()
RaiseEvent onSuccess("<Save Data Completes> บันทึกข้อมูล เรียบร้อย") '--Execute Success
Catch Ex As Exception
_ErrorStatus = "<Error Or Problem> พบปัญหาในการบันทึกข้อมูลลงฐานข้อมูล (ExecuteStoredProc) " & vbCr & vbCr & Ex.Message
Finally
Call CloseDB()
End Try

End Sub

'Public Sub CreateParam(ByRef Cmd As OleDbCommand, ByVal StrType As String)
' 'T:Text, M:Memo, Y:Currency, D:Datetime, I:Integer, S:Single, B:Boolean
' Dim i As Integer
' Dim j As String
' For i = 1 To Len(StrType)
' j = UCase(Mid(StrType, i, 1))
' Dim P1 As New OleDbParameter()
' P1.ParameterName = "@P" & i
' Select Case j
' Case "T"
' P1.OleDbType = OleDbType.VarWChar
' Case "M"
' P1.OleDbType = OleDbType.LongVarWChar
' Case "Y"
' P1.OleDbType = OleDbType.Currency
' Case "D"
' P1.OleDbType = OleDbType.Date
' Case "I"
' P1.OleDbType = OleDbType.Integer
' Case "S"
' P1.OleDbType = OleDbType.Decimal
' Case "B"
' P1.OleDbType = OleDbType.Boolean
' End Select
' Cmd.Parameters.Add(P1)
' Next
'End Sub



#End Region '--DBClass SQLServer

#Region "CodeGenerator"
Public Function Gencode(ByVal comcode As String, ByVal orgcode As String, ByVal rectype As String) As String
Dim md As New MDClass
Dim GencodeTable As New DataTable
Dim runno As Integer
Dim YYYY As String
Dim Codegen As String = ""
If Year(Now) > 2500 Then
'--พ.ศ.
YYYY = (Year(Now) - 543).ToString.Trim
Else
'--ค.ศ
YYYY = Year(Now).ToString.Trim
End If
strSql = ""
strSql &= " Select RUN_NO "
strSql &= " ,RUN_DATE "
strSql &= " From Mena_General..GEN_MSRUNNINGNO "
strSql &= " Where COMP_CODE = '" & comcode & "'"
strSql &= " And ORG_CODE = '" & orgcode & "'"
strSql &= " And RUN_DOC_TYPE = '" & rectype & "'"
strSql &= " And RUN_DATE = '" & YYYY & "'"
Dim Dt As DataTable
Dt = GetDataTable(strSql)
If GetIsError = False AndAlso Dt.Rows.Count > 0 Then
runno = CInt(Dt.Rows(0)("RUN_NO"))
'YYYY = CStr(Dt.Rows(0)("RUN_DATE"))
runno += 1
'================================================
Codegen = rectype & Mid(YYYY, 3, 2) & Right("000000" & runno.ToString.Trim, 6)
'================================================
strSql = "" 'Update ตารางทันทีที่ทำการขอเลขเสร็จ
strSql &= " Update Mena_General..GEN_MSRUNNINGNO set "
strSql &= " RUN_NO = '" & runno & "',"
strSql &= " UPDATE_NAME = '" & Session("Emp_Update").ToString & "',"
strSql &= " UPDATE_DATE ='" & md.chkdate("MDY") & "' "
strSql &= " Where COMP_CODE = '" & comcode & "'"
strSql &= " And ORG_CODE = '" & orgcode & "'"
strSql &= " And RUN_DOC_TYPE = '" & rectype & "'"
Execute(strSql)
Else
Codegen = rectype & Right(YYYY, 2) & "000001"
strSql = "INSERT INTO Mena_General..GEN_MSRUNNINGNO "
strSql = strSql & "(COMP_CODE,ORG_CODE,RUN_DATE,"
strSql = strSql & "RUN_DOC_TYPE,RUN_NO,UPDATE_NAME,UPDATE_DATE) VALUES "
strSql = strSql & "( '" & comcode & " ','" & orgcode & "','" & YYYY & "','" & rectype & "',"
strSql = strSql & "'1', '" & Session("Emp_Update").ToString.Trim & "',' " & md.chkdate("MDY") & "') "
Execute(strSql)
End If
Return Codegen
End Function
'function for เลือกวันที่จาก เครื่อง server
Public Function Select_DateTimeServer() As String
Dim xx As String = ""
strSql = ""
strSql &= " Select Getdate()as xx"
Dim Dt As DataTable
Dt = GetDataTable(strSql)
If GetIsError = False AndAlso Dt.Rows.Count > 0 Then
xx = CStr(Dt.Rows(0).Item("xx"))
End If
Return xx
End Function
#End Region '---CodeGenerator

#Region "Others"
Public ReadOnly Property ErrorStatus() As String
'--แสดง Error Message ในการ Connection Database--'
Get
Return _ErrorStatus
End Get
End Property

Public ReadOnly Property GetIsError() As Boolean
'--ตรวจสอบ Error การ Connection Database--'
Get
Dim errmsg As Boolean = False
If Not Me._ErrorStatus Is Nothing Then
If Me._ErrorStatus.Length > 0 Then
errmsg = True
End If
End If
Return errmsg
End Get
End Property

Private Sub ShowError()
'--แสดง Message BOX Error การ Connection Database--'
If Not IsNothing(_ErrorStatus) Then
MsgBox(_ErrorStatus)
RaiseEvent onDBError(_ErrorStatus)
End If
End Sub
#End Region '---Others

#Region "GetIPAddress"
'Private Function GetIPAddress() As String '--แบบที่ 1
' Dim MyManagementClass As New ManagementClass("Win32_NetworkAdapterConfiguration")
' Dim MyManagementObjectCollection As ManagementObjectCollection = MyManagementClass.GetInstances()
' Dim MyManagementObject As ManagementObject
' Dim StrIP As String = ""
' For Each MyManagementObject In MyManagementObjectCollection
' If CBool(MyManagementObject.Item("IPEnabled").ToString) = True Then 'รับค่า IP
' Dim IP1() As String = CType(MyManagementObject.Item("IPAddress"), String())
' 'MessageBox.Show("ip address " & IP(0))
' 'MessageBox.Show("MAC address " & MyManagementObject.Item("MacAddress").ToString())
' 'GetIPAddress = IP(0)
' StrIP = IP1(0)
' Exit For
' Else
' StrIP = ""
' End If
' Next
' Return StrIP
'End Function
'Private Function GetIPAddress() As String '--แบบที่ 2
' Dim sHostName As String
' Dim i As Integer
' sHostName = System.Net.Dns.GetHostName()
' Dim ipE As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(sHostName)
' Dim IpA() As System.Net.IPAddress = ipE.AddressList
' For i = 0 To IpA.GetUpperBound(0)
' Console.Write("IP Address {0}: {1} ", i, IpA(i).ToString)
' Next
' Return IpA(0).ToString
'End Function
'Sub GetIPAddress() '--แบบที่ 3
' Dim myHost As String = System.Net.Dns.GetHostName()
' IP = System.Net.Dns.GetHostEntry(myHost).AddressList(0).ToString
' IP = Left(IP, 6) & ".0.1"
'End Sub
Public ReadOnly Property GetIP() As String
'--แสดง IP ของเครื่องที่เรียกใช้โปรแกรม--'
'G_HostIP = DB.GetIP '--เริ่มเรียกใช้
Get
'HostIP = GetIPAddress()
Return HostIP
End Get
End Property
#End Region '--"GetIPAddress"

#Region "USE"
'
'
'--ส่วนวิธีใช้ให้ประกาศobject ของ class DBClass แบบนี้
'Public Class Test
'-- แบบที่ 1 วางไว้ที่หัว Form (เรียก Database ทันที่)
' Private WithEvents DB As New DBClass
'
'-- แบบที่ 2 วางไว้ที่หัว Form (เรียก Database ภายหลัง)
' Private WithEvents DB As DBClass
' DB = New DBClass '--เรียก Database

' Private WithEvents คือ เป็นการสั่งให้ Object เพิ่ม Event เข้ามา เช่น เมื่อเขียน
' เช่น
' Private WithEvents oRS As New ADODB.Recordset
' แล้วไปที่ดูที่ ListBox ของ Object จะเห็น oRS เมื่อเลือกแล้วคลิกที่ ListBox ของ Event
' ก็จะเห็น Event ต่างๆ ให้เลือก Code ได้ แต่ถ้าไม่มี WithEvents เราจะไม่เห็น oRS ใน ListBox
'End Class
'
'
'--ส่วนวิธีใช้ก็
'Private Sub DBManager_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Dim DS As DataSet
' DS = DB.GetDataSet("select * from xxx")
' If DB.GetIsError = False Then
' '---
' End If
'
' หรือ
'
' Dim Dr As SqlClient.SqlDataReader
' Dr = DB.GetDataReader(strSql)
' If DB.GetIsError = False andalso dt.row.count > 0 Then
' If Dr.HasRows Then
' While Dr.Read()
' MsgBox("xx -->> " & Dr(0).ToString())
' End While
' End If
' End If
' Dr.Close()
'End Sub
'
'
'--การจับ Event ของ Class
'Private Sub onQueryError(ByVal strError As String) Handles myDB.onDBError
' MsgBox(strError)
'End Sub
'Private Sub onSuccess(ByVal strMessage As String) Handles myDB.onSuccess
' MsgBox(strMessage)
'End Sub
'
'If DB.GetIsError = True Then
' MsgBox(myDB.ErrorStatus)
'End If
'
#End Region '--"วิธีเรียกใช้ USE"

#Region "Fixsection"
'1.ถ้าทำการเพิ่มรหัสลูกค้าใหม่แล้วกด _keypress แล้วทำการ search หาข้อมูลในฐานข้อมูลถ้าหากมีข้อมูล
' ให้ขึ้น messaagebox บอกว่ามีข้อมูลอยู่แล้ว เช่น รหัสลูกค้า 1122 มีอยู่ในฐานข้อมูลแล้วไม่สามารถเพิ่มใหม่ได้อีก
'2.ถ้าอยู่ในสถานะ แก้ไข ลบ Textbox ที่เป็น Primary key และปุ่มที่ Text นั้นต้องทำงานไม่ได้
'3.เมื่อ key ข้อมูลในช่อง Textbox ที่เป็น Primary key เสร็จต้อง Lock ทันทีถ้าหา Key ผิดต้องกดปุ่มยกเลิกแล้วค่อยคีย์เข้าไปไหม่
#End Region '--"Fixsection"

End Class
Date : 2009-08-26 16:00:58 By : ody
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ถามเรื่อง Code ASP.NET คับบ ติด Error คับบ คือ Code ผมประมาณว่า sp:GridView
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 00
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 อัตราราคา คลิกที่นี่