ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
Code (VB.NET)
'tr = Conn.BeginTransaction()
Dim sb As New StringBuilder()
sb.Remove(0, sb.Length)
sb.Append("SELECT pro_id,name,unit_price,categories,detail,stock")
sb.Append(" FROM Products")
sb.Append(" WHERE (name LIKE '%" & txtserchtxt.Text & "%')")
Dim sqlproducts As String = sb.ToString()
Dim com As New OleDbCommand()
Dim dr As OleDbDataReader
With com
.CommandType = CommandType.Text
.CommandText = sqlproducts
.Connection = Conn
'.Transaction = tr
.Parameters.Clear()
.Parameters.Add("name", OleDbType.VarChar).Value = txtserchtxt.Text.Trim()
dr = .ExecuteReader()
If dr.HasRows Then
dr.Read()
txtpro_id.Text = dr.GetString(dr.GetOrdinal("pro_id"))
txtname_p.Text = dr.GetString(dr.GetOrdinal("name"))
txtcategories_p.Text = dr.GetString(dr.GetOrdinal("categories"))
txtprice_p.Text = dr.GetString(dr.GetOrdinal("unit_price"))
txtdetail_p.Text = dr.GetString(dr.GetOrdinal("detail"))
txtstock_p.Text = dr.GetString(dr.GetOrdinal("stock"))
Else
MessageBox.Show("ไม่มีชื่อสินค้า ตามที่คุณต้องการ !!!", "ผลการค้นหา", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End With
dr.Close()