2
オブジェクトコードです:私はそれを実行するとデータリストコントロール:ADO.NETとの結合はここで
private void ShowPossiblePurchases(string CategoryName)
{
string selectSQL = "SELECT TOP 2 * FROM Menu WHERE [email protected] ORDER BY NEWID()";
SqlCommand cmd = new SqlCommand(selectSQL, connection);
cmd.Parameters.AddWithValue("@CategoryName", CategoryName);
SqlDataReader reader;
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add("Products");
myDataSet.Tables["Products"].Columns.Add("ProductID");
myDataSet.Tables["Products"].Columns.Add("CategoryID");
myDataSet.Tables["Products"].Columns.Add("ProductName");
myDataSet.Tables["Products"].Columns.Add("Price");
DataList DataList1 = (DataList)lgnView.FindControl("DataList1");
try
{
connection.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
DataRow rowNew = myDataSet.Tables["Products"].NewRow();
rowNew["ProductID"] = reader["ProductID"];
rowNew["CategoryID"] = reader["CategoryID"];
rowNew["ProductName"] = reader["ProductName"];
rowNew["Price"] = reader["Price"];
myDataSet.Tables["Products"].Rows.Add(rowNew);
}
DataList1.DataSource = myDataSet.Tables["Products"];
DataList1.DataBind();
}
catch(Exception ex)
{
Label lblError = (Label)lgnView.FindControl("lblError");
lblError.Text = ex.Message;
}
finally
{
connection.Close();
}
}
、何も起こりません。何が間違っているのですか?
実際に例外が何を伝えているかをチェックするのではなく、「false」を返します。 – MartW
catchブロックに例外を指定していないのはなぜですか?それは何が起きているかを判断するのに役立つでしょう –
DataList1.DataMember = "製品"の場合にのみ – mslliviu