用户必须从下拉列表中选择一个值,然后应该获取数据库中的数据并将其放入页面上的标签(即BookName,Author,Rating,Comments).
这是我到目前为止,但它不起作用:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);
con.Open();
OleDbCommand cmdReade = new OleDbCommand();
OleDbDataReader reader = null;
OleDbCommand cmdSelect = new OleDbCommand(@"SELECT * FROM Books WHERE bookName = '" + DdlSelectBook.SelectedItem.ToString() + "'");
while (reader.Read())
{
lblBookName.Text = reader["bookName"].ToString();
lblAuthor.Text = reader["Author"].ToString();
lblRating.Text = reader["Rating"].ToString();
lblComments.Text = reader["Comments"].ToString();
}
}
}
Run Code Online (Sandbox Code Playgroud)
数据库表是BookName
,Author
和Rating
,Comments
还有一个图像应该从项目中与显示的书匹配的文件夹中显示.
我的代码出了什么问题?
用户必须提供起始点并指示序列应该是升序还是降序.到目前为止它开始计数并且永不停止.如何在将其递增10之后使其停止.我是否会使用if语句让用户选择使其升序或降序?
class Program
{
static void Main(string[] args)
{
int val;
Console.WriteLine("Please enter a number!");
val = Int32.Parse(Console.ReadLine());
for (int i = val; i <= (val + 10); val++)
Console.WriteLine(val);
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)