 |
|
มันขึ้น Error แบบนี้ must declare the variable '@___' |
|
 |
|
|
 |
 |
|
เป็นการ error เมื่อคลิกที่ปุ่ม บันทึกค่ะ

Code (VBScript) โค้ดตรงส่วนของการSave
Sub SaveItemHeader()
'///////////////////////////////////////////////////
Dim sb As New StringBuilder
Dim com As New OleDbCommand
Me.Cursor = Cursors.WaitCursor
Try
Me.ConnectDB()
'///////////////////////////////////////////////////
sb.Remove(0, sb.Length)
sb.Append("INSERT INTO Buy(Code_Buy,Cat,Date1,Date2,Reason,Checks)")
sb.Append(" VALUES (@CodeBuy,@Cat,@Date1,@Date2,@Reason,@Checks)")
Dim sqlsave As String
sqlsave = sb.ToString()
With com
.CommandText = sqlsave
.Parameters.Clear()
.Parameters.AddWithValue("@CodeBuy", OleDbType.VarChar).Value = Me.TextBox3.Text
.Parameters.AddWithValue("@Cat", OleDbType.VarChar).Value = Me.ComboBox1.SelectedValue
.Parameters.AddWithValue("@Date1", OleDbType.Date).Value = Me.DateTimePicker1.Value.Date
.Parameters.AddWithValue("@Date2", OleDbType.Date).Value = Me.DateTimePicker2.Value.Date
.Parameters.AddWithValue("@Reason", OleDbType.VarChar).Value = Val(Me.TextBox1.Text)
.Parameters.AddWithValue("@Checks", OleDbType.VarChar).Value = Val(Me.TextBox2.Text)
.CommandType = CommandType.Text
.Connection = Conn
.ExecuteNonQuery()
End With
Me.ClearItemDetial()
Me.Cursor = Cursors.Default
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error ไม่สามารถบันทึกข้อมูลได้")
Exit Try
Exit Sub
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
เป็นการ error เมื่อคลิกที่ปุ่มแก้ไขค่ะ

Code (VBScript) โค้ดตรงส่วนของการUpdate
Sub UpdateItem()
'///////////////////////////////////////////////////
Dim sb As New StringBuilder
Dim com As New OleDbCommand
Me.Cursor = Cursors.WaitCursor
Try
Me.ConnectDB()
Dim sqlSave As String
sqlSave = sb.ToString()
'///////////////////////////////////////////////////
sb.Remove(0, sb.Length)
sb.Append("UPDATE Buy")
sb.Append(" SET Cat=@Cat,")
sb.Append(" Date1=@Date1,")
sb.Append(" Date2=@Date2,")
sb.Append(" Reason=@Reason,")
sb.Append(" Checks=@Checks,")
sb.Append(" Code_Buy=@CodeBuy,")
sqlSave = sb.ToString()
With com
.CommandText = sqlSave
.CommandType = CommandType.Text
.Connection = Conn
.Parameters.Clear()
.Parameters.AddWithValue("@Cat", OleDbType.VarChar).Value = Me.ComboBox1.SelectedValue
.Parameters.AddWithValue("@Date1", OleDbType.Date).Value = Format(Me.DateTimePicker1.Value, "dd/MM/yyyy")
.Parameters.AddWithValue("@Reason", OleDbType.VarChar).Value = Val(Me.TextBox1.Text)
.Parameters.AddWithValue("@Date2", OleDbType.Date).Value = Format(Me.DateTimePicker2.Value, "dd/MM/yyyy")
.Parameters.AddWithValue("@Checks", OleDbType.VarChar).Value = Val(Me.TextBox2.Text)
.Parameters.AddWithValue("@CodeBuy", OleDbType.VarChar).Value = Trim(Me.TextBox3.Text)
.ExecuteNonQuery()
End With
Me.Cursor = Cursors.Default
Me.ClearItemDetial()
Me.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error ไม่สามารถปรับปรุงรายการได้zzzzzzzzzzzz")
Exit Try
Exit Sub
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
Tag : .NET, VS 2008 (.NET 3.x)
|
ประวัติการแก้ไข 2011-10-27 16:18:16 2011-10-27 16:20:28
|
 |
 |
 |
 |
Date :
2011-10-27 16:07:28 |
By :
sinlukploy |
View :
1238 |
Reply :
13 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

อันนี้เป็นฐานข้อมูลนะค่ะ ลองดูทุกที่แล้วตัวอักษรก็ตรงกันหมด ไม่ทราบว่าต้องแก้ไขตรงไหนอีกบ้าง รบกวนทีนะค่ะ
|
 |
 |
 |
 |
Date :
2011-10-27 16:14:35 |
By :
sinlukploy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ฮือๆๆๆๆ ขอโทษด้วย ที่ตอนนี้ยิ่งดูก็ยิ่ง งง ช่วยบอกเจาะจงเลยได้ไหมค่ะว่าต้องเพิ่มหรือดัดแปลงตรงไหน
|
 |
 |
 |
 |
Date :
2011-10-27 16:51:27 |
By :
sinlukploy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าใช้
.Parameters.Add(New OleDbParameter("@CodeBuy", Me.TextBox3.Text))
จะได้ไหมอะครับ...
|
ประวัติการแก้ไข 2011-10-27 17:46:26 2011-10-27 18:11:25
 |
 |
 |
 |
Date :
2011-10-27 17:42:09 |
By :
armmer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแล้วค่ะ ก็ยังไม่ได้

|
 |
 |
 |
 |
Date :
2011-10-27 17:58:52 |
By :
sinlukploy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง Debug ตรง
Code (VB.NET)
Me.ComboBox1.SelectedValue
ออกมาว่ามีค่าหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2011-10-27 19:54:19 |
By :
Cyg |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีค่าปกตินะค่ะ จะมีปัญหาก็ต่อเมื่อ กดปุ่มบันทึกอ่ะ
|
 |
 |
 |
 |
Date :
2011-10-28 08:39:43 |
By :
sinlukploy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Catch ex As Exception
ลองใหม่อีกรอบ มัน error ตรงโค้ดส่วนนี้อ่ะค่ะ
|
 |
 |
 |
 |
Date :
2011-10-28 09:06:14 |
By :
sinlukploy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
http://science.bu.ac.th/board/index.php?topic=918.0
พออ่านลิ้งนี้ก็เข้าใจแล้วค่ะ ว่า Catch ex As Exception มันหมายความว่าไง แต่ก็ยังหาจุด error ด้านบนไม่เจอเลย
|
 |
 |
 |
 |
Date :
2011-10-28 09:18:02 |
By :
sinlukploy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองไม่ใช่ พารามิเตอร์ บันทึกได้ซะงั้น
แต่อยากรู้วิธีที่ทำให้ พารามิเตอร์ ส่งค่าขึ้นไป
ทำยังไงหรอ ค่ะ ช่วยทีนะค่ะ
ใครรู้ช่วยหน่อยค่ะ ลองทุกแบบแล้วไม่รุ้ติดโค้ดตรง
ไหนอีก ขอร้องหล่ะนะค่ะ
|
ประวัติการแก้ไข 2011-10-28 11:56:59 2011-10-28 18:39:14
 |
 |
 |
 |
Date :
2011-10-28 11:56:08 |
By :
sinlukploy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim sb As New StringBuilder
Dim com As New SqlCommand
Dim Conn As New SqlConnection()
Dim strCon As String = "Data Source=Database\SQLEXPRESS;Initial Catalog=DatabaseName;User ID=xx;Password=xxx;Integrated Security=false"
Dim sqlSave As String
sb = New StringBuilder
sb.Append("UPDATE Buy")
sb.Append(" SET Cat=@Cat,")
sb.Append(" Date1=@Date1,")
sb.Append(" Date2=@Date2,")
sb.Append(" Reason=@Reason,")
sb.Append(" Checks=@Checks,")
sb.Append(" Code_Buy=@CodeBuy")
sqlSave = sb.ToString()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strCon
.Open()
End With
Try
With com
.CommandType = CommandType.Text
.Connection = Conn
.Parameters.Clear()
.CommandText = sqlSave
.Transaction = tr
.Parameters.Add("@Cat", SqlDbType.VarChar).Value = ComboBox1.SelectedValue
.Parameters.Add("@Date1", SqlDbType.Date).Value = Format(Me.DateTimePicker1.Value, "dd/MM/yyyy")
.Parameters.Add("@Reason", SqlDbType.VarChar).Value = Val(Me.TextBox1.Text)
.Parameters.Add("@Date2", SqlDbType.Date).Value = Format(Me.DateTimePicker2.Value, "dd/MM/yyyy")
.Parameters.Add("@Checks", SqlDbType.VarChar).Value = Val(Me.TextBox2.Text)
.Parameters.Add("@CodeBuy", SqlDbType.VarChar).Value = Trim(Me.TextBox3.Text)
.ExecuteNonQuery()
MsgBox("บันทึกข้อมูลเรียร้อยแล้ว", MsgBoxStyle.Information, "ระบบแจ้งว่า")
End With
Catch ex As Exception
MsgBox("พบข้อผิดพลาดระหว่างบันทึกข้อมูล", MsgBoxStyle.Exclamation, "ระบบแจ้งว่า")
End Try
|
 |
 |
 |
 |
Date :
2011-10-28 23:54:59 |
By :
msorawich |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้สามารถเอาไปดัดแปลงใช้กับ OleDb ได้ใช้ไหมค่ะ
|
 |
 |
 |
 |
Date :
2011-10-29 15:18:40 |
By :
sinlukploy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้สำหรับ Ole ครับ
Code (VB.NET)
'*** Insert to Database ***'
Dim objConn As New OleDbConnection
Dim strConnString, strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
Server.MapPath("App_Data/mydatabase.mdb")&";Jet OLEDB:Database Password=;"
strSQL = "INSERT INTO files (Name,FilesName,FilesType) " & _
" VALUES " & _
" (@sName,@sFilesName,@sFilesType)"
objConn.ConnectionString = strConnString
objConn.Open()
Dim objCmd As New OleDbCommand(strSQL, objConn)
objCmd.Parameters.Add("@sName", OleDbType.VarChar).Value = Me.txtName.Text
objCmd.Parameters.Add("@sFilesName", OleDbType.Binary).Value = imbByte
objCmd.Parameters.Add("@sFilesType", OleDbType.VarChar).Value = strMIME
objCmd.ExecuteNonQuery()
objConn.Close()
objConn = Nothing
Go to : ASP.NET Access BLOB Binary Data and Parameterized Query
Go to : (C#) ASP.NET System.Data.Odbc - Parameter Query (OdbcParameter)
|
 |
 |
 |
 |
Date :
2011-10-30 08:00:23 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|