Select productid,
(
Select name
From menu
Where id = productid
) As Foodname,
price,
quantity,
price * quantity As total
From salesdetail
Where salesid = (
Select id
From booking
Where secret = 'ypnok3bd'
And id = 'SSD00000000000000001'
);
DataBinding:' System.Data.DataRowView'不包含名称为' productID'的属性。我检查过这些字段是否正确,但为什么它仍然不能?
<table border="1">
<tr>
<td>Food ID</td>
<td>Food Name</td>
<td>Quantity</td>
<td>Price</td>
<td>Total</td>
</tr>
<asp:ListView ID="listView1" runat="server">
<ItemTemplate>
<tr>
<td><%# Eval("productID") %></td>
<td><%# Eval("Foodname") %></td>
<td><%# Eval("quantity") %></td>
<td><%# Eval("price") %></td>
<td><%# Eval("total") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
</table>
答案 0 :(得分:0)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using System.IO;
using System.Text;
using System.Data;
using System.Configuration;
public partial class check : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection connection = new MySqlConnection();
MySqlCommand cmmd = new MySqlCommand();
connection.ConnectionString = "SERVER=localhost;DATABASE=pf;UID=root;PASSWORD=password;";
connection.Open();
string cmdText = "SELECT * FROM booking where secret = '"+ txtcode.Text + "' and id = '"+ txtorid.Text +"'";
MySqlDataAdapter adapt = new MySqlDataAdapter(cmdText, connection);
DataTable t = new DataTable();
adapt.Fill(t);
listView.DataSource = t;
listView.DataBind();
listView.Visible = true;
connection.Close();
//MySqlConnection Conn = new MySqlConnection("Server=localhost;Database=pf;Uid=root;Pwd=password;");
//MySqlCommand Command = new MySqlCommand();
//Conn.Open();
//Command.Connection = Conn;
//Command.CommandText = "SELECT productid, (select name from menu where id = productid)as Foodname, price, quantity, price * quantity as total from salesdetail where salesid = (select id from booking where secret = 'ypnok3bd' and id = 'SSD00000000000000001') ";
////string productid = Command.ExecuteScalar().ToString();
////string Foodname = Command.ExecuteScalar().ToString();
////string price = Command.ExecuteScalar().ToString();
////string total = Command.ExecuteScalar().ToString();
//DataTable d = new DataTable();
//adapt.Fill(d);
//listView1.DataSource = d;
//listView1.DataBind();
//listView1.Visible = true;
//Conn.Close();
}
protected void btncheck_Click(object sender, EventArgs e)
{
}
}