 |
|
Code (VB.NET)
Dim Count As Integer
For iSum = 0 To DataGridView1.RowCount - 2
dtReader.Close()
variableGoodCode = DataGridView1.Rows(iSum).Cells("goodcode").Value
variableDocuNo = DataGridView1.Rows(iSum).Cells("docuno").Value
variableSerial = DataGridView1.Rows(iSum).Cells("serialno").Value
objCMD.CommandText = "select count (DocuCopyNo) AS CountDocuno from WHHD where DocuCopyNo = '" & variableDocuNo & "'"
dtReader = objCMD.ExecuteReader
If dtReader.HasRows Then
While dtReader.Read()
Count = dtReader("CountDocuNo")
If Count = 0 Then
'Variable For Save
MaxDocuID = GetMaxDocuID()
CustID = GetCustID(variableDocuNo)
DocuNo = GetDocuNo()
SubTypeID = 50000
BrchID = GetBrchID(variableDocuNo)
DocuType = 1702
DODPNo = DocuNo
DocuCopyNo = variableDocuNo
DocuCopyType = 104
DocuFlag = "Y"
RefID = GetRefID(variableDocuNo)
Postdocutype = 107
DocuStatus = "N"
AlertFlag = "N"
DateInsert = GetDate()
dtReader.Close() '******
strSQL = "INSERT INTO WHHD(DocuID,CustID,DocuNo,SubTypeID,DocuDate,BrchID,DocuType,DODPNo,DocuCopyDate,DocuCopyNo,DocuCopyType,DocuFlag,RefID,Postdocutype,DocuStatus,AlertFlag) VALUES ('" & MaxDocuID & "','" & CustID & "','" & DocuNo & "','" & SubTypeID & "',getdate(),'" & BrchID & "','" & DocuType & "','" & DODPNo & "',getdate(),'" & DocuCopyNo & "','" & DocuCopyType & "','" & DocuFlag & "','" & RefID & "','" & Postdocutype & "','" & DocuStatus & "','" & AlertFlag & "')"
objCMD = New SqlCommand(strSQL, conn)
objCMD.ExecuteNonQuery()
End If
End While
End If
Next
ตรงที่ ****** ถ้าไม่ close datareader จะทำให้ไม่สามารถ insert ข้อมูลได้
แต่ถ้า close datareader ตรง If dtReader.HasRows ก็จะ Error ค่ะ
Tag : .NET, Ms SQL Server 2008, Excel (Excel.Application), Win (Windows App), VS 2010 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2014-06-17 09:37:36 |
By :
chariyamat |
View :
1249 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |