ช่วยดูโค้ดให้หน่อยคับ มัน error อะคับผมไม่เข้าใจอะคับช่วยดูให้หน่อยนะคับ Invalid attempt to MetaData when reader is closed.
Code (VB.NET)
'############################## Update StorkDLGB ###########################################
Sql = "SELECT TOP 1 SDLGB FROM StorkDLGB ORDER BY SDLGB DESC"
With Com
.CommandType = CommandType.Text
.CommandText = Sql
.Connection = Conn
'dr = .ExecuteReader()
'SeriNumberSDLGB = dr.Item("SDLGB").ToString()
'If dr.HasRows Then
'dr.Read()
'ReadId = dr.Item("SDLGB").ToString()
'NewId = CInt(ReadId) + 1
'SeriNumberSDLGB = NewId.ToString("00000")
'Else
'SeriNumberSDLGB = "00001"
'End If
If SeriNumberSDLGB = vbNullString Then
' dr.Read()
SeriNumberSDLGB = NewId.ToString("00001")
Else
ReadId = dr.Item("SDLGB").ToString()
NewId = CInt(ReadId) + 1
SeriNumberSDLGB = NewId.ToString("00000")
End If
End With
dr.Close()
Sql = "INSERT INTO StorkDLGB(SDLGB,OvenNumber,BarCode,LotNo,Id_Member,Id_Longan,DateAdd,TotalWeightLonganFresh)"
Sql &= " VALUES(@SDLGB,@OvenNumber,@BarCode,@LotNo,@Id_Member,@Id_Longan,@DateAdd,@TotalWeightLonganFresh)"
With Com
.CommandText = Sql
.Parameters.Clear()
.Parameters.Add("@SDLGB", SqlDbType.NVarChar).Value = SeriNumberSDLGB
.Parameters.Add("@OvenNumber", SqlDbType.NVarChar).Value = cboOvenNumber.SelectedValue()
.Parameters.Add("@BarCode", SqlDbType.NVarChar).Value = TextBox1.Text.ToString & TextBox3.Text.ToString & "31"
.Parameters.Add("@LotNo", SqlDbType.NVarChar).Value = CStr(dgvDryingOrganicLonganFleshGoldenOven.Rows(i).Cells(2).Value)
.Parameters.Add("@Id_Member", SqlDbType.NVarChar).Value = CStr(dgvDryingOrganicLonganFleshGoldenOven.Rows(i).Cells(0).Value).Remove(3, 10)
.Parameters.Add("@Id_Longan", SqlDbType.NVarChar).Value = "31"
.Parameters.Add("@DateAdd", SqlDbType.DateTime).Value = CDate(dgvDryingOrganicLonganFleshGoldenOven.Rows(i).Cells(1).Value)
.Parameters.Add("@TotalWeightLonganFresh", SqlDbType.Float).Value = CStr(dgvDryingOrganicLonganFleshGoldenOven.Rows(i).Cells(4).Value)
'.Parameters.Add("@ID_DetailGroup", SqlDbType.NVarChar).Value = TextBox1.Text.Trim()
.ExecuteNonQuery()
End With
มัน error ว่า
ช่วยดูให้หน่อยคับTag : .NET, Ms SQL Server 2005, VB.NET
Date :
2011-11-28 21:53:50
By :
มาเอดะ
View :
798
Reply :
1
ให้ใช้การอ่านแบบ DataTable หรือ DataSet แทน DataReader ครับ
Date :
2011-11-29 13:22:37
By :
webmaster
Load balance : Server 02