需要帮助在数据库中的网页上显示数据 [英] Need help display data on a web page from a database

查看:54
本文介绍了需要帮助在数据库中的网页上显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我的社区很棒,请提供帮助,以将数据库中的数据显示到网页中.我正在构建一个演示机场预订网络应用程序.我在页面上有一些下拉列表,其中显示了您可以飞往的航线.我想当用户单击一个按钮时,它将向用户显示将在特定日期离开机场的所有航班,这将使页面能够发回到服务器并返回与用户选择的所有航班相似的所有航班制作.不知道该怎么做,请给我帮助,谢谢
我已经能够编写与用户选择的内容匹配的查询字符串,但是现在的问题是如何在另一页上显示数据库的搜索结果.这是我到目前为止的代码.目标是使其显示在findFlight.aspx页面,但我不知道该怎么做,如果有人可以向我提供任何帮助,我将不胜感激.
谢谢.



受保护的子buttFindFlight_Click(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理buttFindFlight.Click
昏暗conn作为新的SqlConnection
昏暗的cmd作为新的SqlCommand
Dim str As String
conn.ConnectionString = ConfigurationManager.ConnectionStrings("AirportReservationSystemConnectionString").ConnectionString
cmd.Connection = conn
conn.Open()
cmd.CommandType = CommandType.Text



str =选择LeavPlace作为出发地点,DestPlace作为目的地,LeaveDate作为从DailyFlightInfo出发的地点,其中LeavPlace = @ Leav和DestPlace = @ Dest"
cmd.CommandText = str
cmd.Parameters.Add(新SqlParameter("@ Leav",SqlDbType.VarChar,50))
cmd.Parameters.Add(新SqlParameter("@ Dest",SqlDbType.VarChar,50))

cmd.Parameters("@ Leav").Value = drpLeaving.SelectedItem.Value
cmd.Parameters("@ Dest").Value = drpGoing.SelectedItem.Value
昏暗的阅读器,如SqlDataReader

reader = cmd.ExecuteReader
在阅读器中.
str&= Convert.ToString(reader.Item("Departing"))
str&= Convert.ToString(reader.Item("Destination"))
str&= Convert.ToString(reader.Item("Departure"))
结束时


Response.Redirect("http://localhost:18705/AIRPORTS/findFlight.aspx")






结束Sub

Hello wonderful community, please i need help displaying data from a database into a web page.I am building a demo airport reservation web application.I have some dropdownlist on the page that displays the route you can fly to.I want to be able to display to users all the flight that will be leaving the airport on a particular day,when they click on a button which will enable the page post back to the server and returns all the flights that are similar to the selection that the user made.Don''t know how to go about it, Please i need help thanks
I have been able to write the query string that matches what the user selected,but the problem now is how to display the search result from the database on another page.this is my code so far.The goal is to make it display on the findFlight.aspx page but i don''t know how to go about that i will be most grateful if anyone can render me any help.
Thanks.



Protected Sub buttFindFlight_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttFindFlight.Click
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
Dim str As String
conn.ConnectionString = ConfigurationManager.ConnectionStrings("AirportReservationSystemConnectionString").ConnectionString
cmd.Connection = conn
conn.Open()
cmd.CommandType = CommandType.Text



str = "select LeavPlace as Departing, DestPlace As Destination, LeaveDate as Departure from DailyFlightInfo where LeavPlace=@Leav And DestPlace =@Dest"
cmd.CommandText = str
cmd.Parameters.Add(New SqlParameter("@Leav", SqlDbType.VarChar, 50))
cmd.Parameters.Add(New SqlParameter("@Dest", SqlDbType.VarChar, 50))

cmd.Parameters("@Leav").Value = drpLeaving.SelectedItem.Value
cmd.Parameters("@Dest").Value = drpGoing.SelectedItem.Value
Dim reader As SqlDataReader

reader = cmd.ExecuteReader
While reader.Read
str &= Convert.ToString(reader.Item("Departing"))
str &= Convert.ToString(reader.Item("Destination"))
str &= Convert.ToString(reader.Item("Departure"))
End While


Response.Redirect("http://localhost:18705/AIRPORTS/findFlight.aspx")






End Sub

推荐答案

hi,

请参阅以下链接
ADO.NET 101:SQL连接 [


refer Following link
ADO.NET 101: SQL Connection[^]

Best Luck


protected void button_Click(object sender, EventArgs e)
   {

datatable dt = "select C1 from tablename where date='12/03/2012 "
   if (dt.Rows.Count > 0 )
   {
        DropDownListid.DataSource = dt;
        DropDownListid.DataBind();
        DropDownListid.Items.Insert(0, "--Select--");
   }
   else
   {
        DropDownListid.DataSource = null;
        DropDownListid.DataBind();
   }
}


这篇关于需要帮助在数据库中的网页上显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆