บันทึก 2 ตารางทำไงคับ คือ มันมี status 2 อันคื สถานะ add edit 2 ครั้ง
Code (VB.NET)
Dim sqlStr As String = ""
If Status = "add" Then
sqlStr &= " Insert into RolCloth(RollRe_Id,RollRe_Date,RollRe_Sec,RollRe_ToSec,DetailRececived,IsRececivedAll,IsNormal,Emp_Id,Total)"
sqlStr &= " Values (@RoleID,@RollDate,@Sen,@tosen,@Detail,@Is,@Innomal,@EMpID,@total)"
ElseIf Status = "edit" Then
sqlStr = "Update RolCloth"
sqlStr &= "set IsRececivedAll = @Is,"
sqlStr &= "Total = @total"
sqlStr &= " where RollRe_Id = @RoleID"
End If
Dim sqlStr1 As String = ""
If Status = "add" Then
sqlStr1 &= " Insert into ReceivesBillRoll(RollRec_Id,RollRe_Id,Roll_Date,Roll_dateReceives,Sectionsender_Id,Sectionapp_Id,IsRececivedAlls,RollRec_Quantity,Emp_Id)"
sqlStr1 &= " Values (@RivID,@RolID,@date,@DateRec,@Ssen,@app,@Is,@Quntity,@Emp)"
ElseIf Status = "edit" Then
sqlStr = "Update ReceivesBillRoll"
sqlStr &= " set RollRe_Id = @RolID,"
sqlStr &= "IsRececivedAlls = @Is,"
sqlStr &= "RollRec_Quantity = @Quntity"
sqlStr &= " where RollRec_Id = @RollID"
End If
error :ExecuteNonQuery: CommandText property has not been initializedTag : - - - -
Date :
2012-02-14 10:46:57
By :
gR
View :
1168
Reply :
3
เอา Code ตรงส่วนนี้มาทั้งหมดครับ
Date :
2012-02-14 11:46:25
By :
webmaster
Code (VB.NET)
If Status = "add" Then
sqlStr &= " Insert into RolCloth(RollRe_Id,RollRe_Date,RollRe_Sec,RollRe_ToSec,DetailRececived,IsRececivedAll,IsNormal,Emp_Id,Total)"
sqlStr &= " Values (@RoleID,@RollDate,@Sen,@tosen,@Detail,@Is,@Innomal,@EMpID,@total)"
ElseIf Status = "edit" Then
sqlStr = "Update RolCloth"
sqlStr &= " set IsRececivedAll = @Is,"
sqlStr &= "Total = @total"
sqlStr &= " where RollRe_Id = @RoleID"
End If
Dim cm1 As New SqlCommand
With cm1
.CommandType = CommandType.Text
.CommandText = sqlStr
.Connection = cn
.Parameters.Clear()
.Parameters.Add("@RoleID", SqlDbType.NVarChar, 14).Value = TxtRID.Text
.Parameters.Add("@RollDate", SqlDbType.DateTime).Value = Date2.Text
.Parameters.Add("@sen", SqlDbType.NVarChar, 15).Value = CBSEC1.SelectedValue
.Parameters.Add("@tosen", SqlDbType.NVarChar, 15).Value = CBSEC3.SelectedValue
.Parameters.Add("@detail", SqlDbType.NVarChar, 50).Value = Txtdetail.Text
If Re1.Checked = True Then
.Parameters.Add("@Is", SqlDbType.Char, 1).Value = "0"
ElseIf Re2.Checked = True Then
.Parameters.Add("@Is", SqlDbType.Char, 1).Value = "1"
ElseIf Re3.Checked = True Then
.Parameters.Add("@Is", SqlDbType.Char, 1).Value = "2"
End If
.Parameters.Add("@Innomal", SqlDbType.Char, 1).Value = "0"
.Parameters.Add("@EMpID", SqlDbType.NVarChar, 10).Value = CBEMP1.SelectedValue
.Parameters.Add("@total", SqlDbType.Float).Value = CSng(Total1.Text)
.ExecuteNonQuery()
End With
'Dim i As Integer = 0
'For i = 0 To ListView1.Items.Count - 1
' Dim ss As String = ""
' ss = " insert into RolClothDetail(RollRe_ID,RolCol_Id,Roll_size,Roll_unit,Roll_Cat,RollRe_Quantity,RollRe_unit,RollRe_Sum)"
' ss += " values (@RollReID,@RolID,@Size,@Unit,@Cat,@Quantity,@unita,@sum)"
' With cm
' .CommandType = CommandType.Text
' .CommandText = ss 'sb.tostring
' .Connection = cn
' .Parameters.Clear()
' .Parameters.Add("@RollReID", SqlDbType.NVarChar, 14).Value = TxtRID.Text
' .Parameters.Add("@RolID", SqlDbType.NVarChar, 8).Value = Me.ListView1.Items(i).SubItems(1).Text.Trim
' .Parameters.Add("@Size", SqlDbType.NVarChar, 5).Value = Me.ListView1.Items(i).SubItems(3).Text.Trim
' .Parameters.Add("@Unit", SqlDbType.NVarChar, 5).Value = Me.ListView1.Items(i).SubItems(4).Text
' .Parameters.Add("@Cat", SqlDbType.NVarChar, 7).Value = Me.ListView1.Items(i).SubItems(5).Text
' .Parameters.Add("@Quantity", SqlDbType.Int).Value = Me.ListView1.Items(i).SubItems(6).Text.Trim
' .Parameters.Add("@unita", SqlDbType.NVarChar, 5).Value = Me.ListView1.Items(i).SubItems(7).Text
' .Parameters.Add("@sum", SqlDbType.Float).Value = Me.ListView1.Items(i).SubItems(8).Text
' .ExecuteNonQuery()
' End With
'Next
Dim sqlStr1 As String = ""
If Status = "add" Then
sqlStr1 &= " Insert into ReceivesBillRoll(RollRec_Id,RollRe_Id,Roll_Date,Roll_dateReceives,Sectionsender_Id,Sectionapp_Id,IsRececivedAlls,RollRec_Quantity,Emp_Id)"
sqlStr1 &= " Values (@RivID,@RolID,@date,@DateRec,@Ssen,@app,@Is,@Quntity,@Emp)"
ElseIf Status = "edit" Then
sqlStr = "Update ReceivesBillRoll"
sqlStr &= " set RollRe_Id = @RolID,"
sqlStr &= "IsRececivedAlls = @Is,"
sqlStr &= "RollRec_Quantity = @Quntity"
sqlStr &= " where RollRec_Id = @RivID"
End If
Dim cm3 As New SqlCommand
With cm3
.CommandType = CommandType.Text
.CommandText = sqlStr1
.Connection = cn
.Parameters.Clear()
.Parameters.Add("@RivID", SqlDbType.NVarChar, 13).Value = TxtreID.Text.Trim
.Parameters.Add("@RolID", SqlDbType.NVarChar, 14).Value = TxtRID.Text.Trim
.Parameters.Add("@date", SqlDbType.DateTime).Value = Datede.Text
.Parameters.Add("@DateRec", SqlDbType.DateTime).Value = Datevi.Text
.Parameters.Add("@Ssen", SqlDbType.NVarChar, 15).Value = CBSCE7.SelectedValue
.Parameters.Add("@app", SqlDbType.NVarChar, 15).Value = CBSEC4.SelectedValue
If RadioButton3.Checked = True Then
.Parameters.Add("@Is", SqlDbType.Char, 1).Value = "0"
ElseIf RadioButton2.Checked = True Then
.Parameters.Add("@Is", SqlDbType.Char, 1).Value = "1"
ElseIf RadioButton1.Checked = True Then
.Parameters.Add("@Is", SqlDbType.Char, 1).Value = "2"
End If
.Parameters.Add("@Innomal", SqlDbType.Char, 1).Value = "0"
.Parameters.Add("@Quntity", SqlDbType.Float).Value = CSng(Total1.Text.Trim)
.Parameters.Add("@Emp", SqlDbType.NVarChar, 10).Value = CBMPE5.SelectedValue
.ExecuteNonQuery()
End With
Dim j As Integer = 0
For j = 0 To ListView1.Items.Count - 1
Dim ss As String = ""
ss = " insert into DetailReceivesBillRoll(RollRec_Id,Roll_Id,Roll_size,Roll_unit,Roll_Cat,Quantity,Roll_units,Roll_sums,Roll_amount,Roll_Receivable,Roll_cancel,Roll_Sum)"
ss += " values (@RollRe_ID,@RolID,@Size,@Unit,@Cat,@Quantity,@unita,@sums,@amount,@REVble,@Rcan,@sum)"
With cm
.CommandType = CommandType.Text
.CommandText = ss 'sb.tostring
.Connection = cn
.Parameters.Clear()
.Parameters.Add("@RollRe_ID", SqlDbType.NVarChar, 13).Value = TxtreID.Text
.Parameters.Add("@RolID", SqlDbType.NVarChar, 8).Value = Me.ListView1.Items(j).SubItems(1).Text.Trim
.Parameters.Add("@Size", SqlDbType.Int).Value = Me.ListView1.Items(j).SubItems(3).Text.Trim
.Parameters.Add("@Unit", SqlDbType.NVarChar, 5).Value = Me.ListView1.Items(j).SubItems(4).Text
.Parameters.Add("@Cat", SqlDbType.NVarChar, 7).Value = Me.ListView1.Items(j).SubItems(5).Text
.Parameters.Add("@Quantity", SqlDbType.Int).Value = Me.ListView1.Items(j).SubItems(6).Text.Trim
.Parameters.Add("@unita", SqlDbType.NVarChar, 5).Value = Me.ListView1.Items(j).SubItems(7).Text
.Parameters.Add("@sums", SqlDbType.Int).Value = Me.ListView1.Items(j).SubItems(8).Text
.Parameters.Add("@amount", SqlDbType.Int).Value = Me.ListView1.Items(j).SubItems(9).Text
.Parameters.Add("@REVble", SqlDbType.Int).Value = Me.ListView1.Items(j).SubItems(10).Text
.Parameters.Add("@Rcan", SqlDbType.Int).Value = Me.ListView1.Items(j).SubItems(11).Text
.Parameters.Add("@sum", SqlDbType.Int).Value = Me.ListView1.Items(j).SubItems(12).Text
.ExecuteNonQuery()
End With
Next
Date :
2012-02-14 12:56:50
By :
laem
Code (VB.NET)
With cm
มันคืออะไรครับ
Date :
2012-02-14 13:08:09
By :
webmaster
Load balance : Server 03