Asp.net 在网格视图中搜索记录
读取记录已解决。我仍然有另一个问题,错误消息仍然保留在正确的顺序id的用户密钥之后Asp.net 在网格视图中搜索记录,asp.net,vb.net,Asp.net,Vb.net,读取记录已解决。我仍然有另一个问题,错误消息仍然保留在正确的顺序id的用户密钥之后 query = "select FoodName, Qty, IngredientName, Quantity, OrderStatus from tblorder, tblorderdetail, tblfood, tblcustomizefooddetail, tblcustomizeingredient, tblordercustomize w
query = "select FoodName, Qty, IngredientName, Quantity, OrderStatus
from tblorder, tblorderdetail, tblfood, tblcustomizefooddetail, tblcustomizeingredient, tblordercustomize
where tblOrder.OrderId = @OrderId and OrderStatus = @OrderStatus and tblorder.OrderId = tblorderdetail.OrderId and tblorderdetail.FoodId = tblfood.FoodId and tblorderdetail.OrderDetailId = tblordercustomize.OrderDetailId and tblfood.FoodId = tblcustomizefooddetail.FoodId and tblcustomizeingredient.IngredientId = tblcustomizefooddetail.IngredientId and tblordercustomize.IngredientId = tblcustomizeingredient.IngredientId"
com = New MySqlCommand(query, conn)
com.Parameters.AddWithValue("@OrderId", txtOrderId.Text)
com.Parameters.AddWithValue("@OrderStatus", "Pending")
Dim sqladapter As New MySqlDataAdapter(com)
sqladapter.Fill(dt)
If dt.Rows.Count Then
GridView1.DataSource = dt
GridView1.DataBind()
Else
Label1.Text = "Order ID Doesn't Exist"
End If
让我们获取您的样本并对其进行修改:
query = "select FoodName, Qty, IngredientName, Quantity, OrderStatus
from tblorder, tblorderdetail, tblfood, tblcustomizefooddetail, tblcustomizeingredient, tblordercustomize
where tblOrder.OrderId = @OrderId and OrderStatus = @OrderStatus and tblorder.OrderId = tblorderdetail.OrderId and tblorderdetail.FoodId = tblfood.FoodId and tblorderdetail.OrderDetailId = tblordercustomize.OrderDetailId and tblfood.FoodId = tblcustomizefooddetail.FoodId and tblcustomizeingredient.IngredientId = tblcustomizefooddetail.IngredientId and tblordercustomize.IngredientId = tblcustomizeingredient.IngredientId"
com = New MySqlCommand(query, conn)
com.Parameters.AddWithValue("@OrderId", txtOrderId.Text)
com.Parameters.AddWithValue("@OrderStatus", "Pending")
Dim adapter as new SqlDataAdapter(com)
adapter.Fill(dt)
if adapter.Tables(0).Rows.Count > 0
GridView1.DataSource = adapter.Tables(0)
GridView1.DataBind()
Else
Label1.Text = "Order ID Doesn't Exist"
End If
您已经在读取第一条记录,因此您将删除第一条记录。为什么不使用SqlDataAdapter并让它为您完成所有的艰苦工作呢?此外,我没有看到您关闭连接,但我怀疑这只是一段代码。可以举一些例子吗?我是新来的你说“只读第一条记录”-这是因为你做了
dr.read
-它读一条记录。然后执行dt.Load(dr)
——它从第二条记录开始读取。一定要使用sqldataadapter
,因为您的目标是获取datatable
。有关示例,请访问MSDN。用谷歌搜索.netsqldataadapter
,你就会在那里。