 |
|
คำนวณแล้วให้ไป updateข้อมูล ลงฐานข้อมูลเลยค่ะ vb2005 |
|
 |
|
|
 |
 |
|
Dim i As Integer
Dim a, b As Date
Dim ans As Double
Dim day As Integer
b = DateTimePicker1.Value
a = DateTimePicker2.Value
'คำนวณหาจำนวนวัน
day = DateDiff(DateInterval.Day, CDate(b), CDate(a))
day = day + 1
Dim SrtQuery As String
SrtQuery = "SELECT * FROM Depreciation "
Dim ws As New CheckSv
Ds = ws.ReadDb(SrtQuery, "ShowID")
For i = 0 To Ds.Tables("ShowID").Rows.Count - 1
Dim cost As Double = Ds.Tables("ShowID").Rows(i)("cost_price")
Dim scrap As Double = Ds.Tables("ShowID").Rows(i)("scrap_value")
Dim rate As Double = Ds.Tables("ShowID").Rows(i)("rate")
Dim depreciation As Double = Ds.Tables("ShowID").Rows(i)("depreciation")
Dim accumulate As Double = Ds.Tables("ShowID").Rows(i)("accumulate_depreciation")
ans = (((cost - scrap) * (rate / 100)) / 365) * day
TextBox2.Text = FormatNumber(ans, 2)
TextBox3.Text = FormatNumber(accumulate + ans, 2)
MsgBox("คำนวณค่าเสื่อมเรียบร้อย", MsgBoxStyle.Exclamation, "Complete")
Next
คือว่าอยากให้เปลี่ยนจาก TextBox2.Text , TextBox3.Text ให้ไป update ลงคอลัมน์ ทั้ง2 คอลัมน์ค่ะ
จะต้องแก้ code ยังไงค่ะ สมมุติว่ามี 10 แถวก็ให้คำนวณแล้วนำไปใส่ในคอลัมน์ทั้ง2คอลัมน์ ทั้ง10แถวค่ะ
ทำโปรเคอยู่ค่ะ vb,sql 2005
Tag : .NET, Ms SQL Server 2005, VS 2005 (.NET 2.x)
|
|
 |
 |
 |
 |
Date :
2010-09-01 15:22:34 |
By :
pumka |
View :
1301 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองตามนี้ดูครับ
dim strUpdate as string 'เพิ่มเข้ามา
dim intCol_A,intCol_B as integer
Dim SrtQuery As String
SrtQuery = "SELECT * FROM Depreciation "
Dim ws As New CheckSv
Ds = ws.ReadDb(SrtQuery, "ShowID")
For i = 0 To Ds.Tables("ShowID").Rows.Count - 1
Dim cost As Double = Ds.Tables("ShowID").Rows(i)("cost_price")
Dim scrap As Double = Ds.Tables("ShowID").Rows(i)("scrap_value")
Dim rate As Double = Ds.Tables("ShowID").Rows(i)("rate")
Dim depreciation As Double = Ds.Tables("ShowID").Rows(i)("depreciation")
Dim accumulate As Double = Ds.Tables("ShowID").Rows(i)("accumulate_depreciation")
ans = (((cost - scrap) * (rate / 100)) / 365) * day
intCol_A = FormatNumber(ans, 2)
intCol_B = FormatNumber(accumulate + ans, 2)
'ไม่รู้ว่า คอลัมทั้ง 2 ชื่อว่ารัย กำหนดเป็น col_a และ col_b แล้วกัน
strUpdate = "update Depreciation set col_a = '" & intCol_A & "',"
strUpdate +="col_b ='" & intCol_B & "'"
strUpdate +=" where id='" & ds.tables("showID").rows(i)("ID").tostring() & "'"
with com
.commandtype = commandtype.text
.commandtext = strUpdate
.connection = conn
.executenonquery()
end with
Next
ไม่แน่ใจว่าถูกหรือเปล่า แต่น่าจะประมาณนี้นะ ไม่ได้เขียนนานแล้ว ผิดตรงไหนก็ ขอ อภัยด้วย
|
ประวัติการแก้ไข 2010-09-01 15:46:17 2010-09-01 15:47:11
 |
 |
 |
 |
Date :
2010-09-01 15:45:01 |
By :
tee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณคุณ tee มากๆนะค่ะ จะลองทำดูค่ะ
|
 |
 |
 |
 |
Date :
2010-09-02 00:41:48 |
By :
pumka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ได้งี้ค่ะ
แต่มัน error ว่า Conversion from string " set depreciation ='" to type 'Double' is not valid.
Dim i As Integer
Dim a, b As Date
Dim ans As Double
Dim day As Integer
b = DateTimePicker1.Value
a = DateTimePicker2.Value
'คำนวณหาจำนวนวัน
day = DateDiff(DateInterval.Day, CDate(b), CDate(a))
day = day + 1
Dim StrAdd As String
Dim depre, acc As Double
Dim SrtQuery As String
SrtQuery = "SELECT * FROM Depreciation "
Dim ws As New CheckSv
Ds = ws.ReadDb(SrtQuery, "ShowID")
For i = 0 To Ds.Tables("ShowID").Rows.Count - 1
Dim cost As Double = Ds.Tables("ShowID").Rows(i)("cost_price")
Dim scrap As Double = Ds.Tables("ShowID").Rows(i)("scrap_value")
Dim rate As Double = Ds.Tables("ShowID").Rows(i)("rate")
Dim depreciation As Double = Ds.Tables("ShowID").Rows(i)("depreciation")
Dim accumulate As Double = Ds.Tables("ShowID").Rows(i)("accumulate_depreciation")
ans = (((cost - scrap) * (rate / 100)) / 365) * day
depre = FormatNumber(ans, 2)
acc = FormatNumber(accumulate + ans, 2)
StrAdd = "update Depreciation"
StrAdd &= " set depreciation ='" + depre + "'," 'error
StrAdd &= " accumulate_depreciation ='" + acc + "'"
StrAdd &= " where code ='" + Ds.Tables("showID").Rows(i)("code").ToString() + "'"
Next
MsgBox("คำนวณค่าเสื่อมเรียบร้อย", MsgBoxStyle.Exclamation, "Complete")
เหมือนว่าเป็น double แล้วบันทึกไม่ได้อ่ะค่ะ ต้องแก้ยังไงดีค่ะ
|
 |
 |
 |
 |
Date :
2010-09-02 22:33:31 |
By :
pumka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|