小编Nir*_*rre的帖子

DataReader + DropDownList ASP.NET项目

用户必须从下拉列表中选择一个值,然后应该获取数据库中的数据并将其放入页面上的标签(即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,AuthorRating,Comments还有一个图像应该从项目中与显示的书匹配的文件夹中显示.

我的代码出了什么问题?

c# asp.net oledb datareader drop-down-menu

1
推荐指数
1
解决办法
722
查看次数

输出一个十个数字的序列到控制台

用户必须提供起始点并指示序列应该是升序还是降序.到目前为止它开始计数并且永不停止.如何在将其递增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)

.net c# loops console-application

-1
推荐指数
1
解决办法
5482
查看次数