Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 1st, 2005, 04:50 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default DropDownList

Hi, I have a dropdownlist for user to select due date of book loan.
But the value that i retrieved fr the selection is individual, date, month and year. How can I assign the 3 values retrieved to a variable named Due_Date?

Code:
Dim Due_Date As DateTime
Dim DueDay, DueMonth, DueYear As Integer
Private Sub ddlDueDay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlDueDay.SelectedIndexChanged
        DueDay = ddlDueDay.SelectedItem.Value
    End Sub

    Private Sub ddlDueMonth_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlDueMonth.SelectedIndexChanged
        DueMonth = ddlDueMonth.SelectedItem.Value
    End Sub

    Private Sub ddlDueYear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlDueYear.SelectedIndexChanged
        DueYear = ddlDueYear.SelectedItem.Value
    End Sub
Thank you.

Irene



 
Old June 1st, 2005, 09:32 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Why not use a calendar control for the selection of the date?

 
Old June 1st, 2005, 10:42 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Due_Date = CDate(CStr(DueMonth) + "/" + CStr(DueDay) + "/" + CStr(DueYear))

I still suggest using a calendar control(even a 3rd party control) for better UI.

 
Old June 1st, 2005, 07:32 PM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, I use Due_Date = CDate(CStr(DueMonth) + "/" + CStr(DueDay) + "/" + CStr(DueYear))

But now when i run the page, i got this error.

Server Error in '/e-library' Application.
--------------------------------------------------------------------------------

Line 1: Incorrect syntax near ','.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near ','.

Source Error:


Line 284: SqlDataAdapter2.SelectCommand.Parameters("@Due_Dat e").Value = Due_Date
Line 285: con.Open()
Line 286: SqlDataAdapter2.SelectCommand.ExecuteNonQuery()
Line 287: con.Close()
Line 288:


Source File: c:\inetpub\wwwroot\e-library\Renew.aspx.vb Line: 286

Stack Trace:


[SqlException: Line 1: Incorrect syntax near ','.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +742
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +196
   e_library.Renew.btnSubmit_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\e-library\Renew.aspx.vb:286
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1292




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

[code]
 Dim DueDay, DueMonth, DueYear As String
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim sql As String
        Dim Title As String
        Dim Due_Date As DateTime
        Dim New_Due_Date As DateTime
        Dim Days As DateTime

        sql = "SELECT * FROM [Waiting_List] WHERE Title= @Title"
        SqlDataAdapter1.SelectCommand.CommandText = sql
        SqlDataAdapter1.SelectCommand.Parameters.Add(New _
            SqlParameter("@Title", SqlDbType.VarChar, 100))
        SqlDataAdapter1.SelectCommand.Parameters("@Title") .Value = _
            txtTitle.Text
        con.Open()
        SqlDataAdapter1.SelectCommand.ExecuteNonQuery()
        con.Close()

        Due_Date = CDate(CStr(DueMonth) + "/" + CStr(DueDay) + "/" + CStr(DueYear))

        If Not Title Is Nothing Then
            lblRenewNotOk.Visible = True
        Else
            sql = "SELECT User_id, Title, Due_Date FROM [BookLoan_Record] WHERE User_id=@User_id, Title= @Title And Due_Date=@Due_Date"
            SqlDataAdapter2.SelectCommand.CommandText = sql
            SqlDataAdapter2.SelectCommand.Parameters.Add(New _
                SqlParameter("@User_id", SqlDbType.Char, 10))
            SqlDataAdapter2.SelectCommand.Parameters.Add(New _
                SqlParameter("@Title", SqlDbType.VarChar, 100))
SqlDataAdapter2.SelectCommand.Parameters.Add(New _
                SqlParameter("@Due_Date", SqlDbType.DateTime, 8))
            SqlDataAdapter2.SelectCommand.Parameters("@User_id ").Value = txtUserID.Text
            SqlDataAdapter2.SelectCommand.Parameters("@Title") .Value = txtTitle.Text
            SqlDataAdapter2.SelectCommand.Parameters("@Due_Dat e").Value = Due_Date
            con.Open()
            SqlDataAdapter2.SelectCommand.ExecuteNonQuery()
            con.Close()

            New_Due_Date = Due_Date.AddDays(7)

            sql = "INSERT INTO Renewal Values (@User_id, @Title, @New_Due_Date)"
            SqlDataAdapter3.InsertCommand.Parameters.Add(New _
                SqlParameter("@User_id", SqlDbType.Char, 10))
            SqlDataAdapter3.InsertCommand.Parameters.Add(New _
                SqlParameter("@Title", SqlDbType.VarChar, 100))
SqlDataAdapter3.InsertCommand.Parameters.Add(New _
                SqlParameter("@New_Due_Date", SqlDbType.DateTime, 8))
            SqlDataAdapter3.InsertCommand.Parameters("@User_id ").Value = txtUserID.Text
            SqlDataAdapter3.InsertCommand.Parameters("@Title") .Value = txtTitle.Text
SqlDataAdapter3.InsertCommand.Parameters("@New_Due _Date").Value = New_Due_Date

            con.Open()
            SqlDataAdapter3.InsertCommand.ExecuteNonQuery()
            con.Close()
End If
    End Sub

I still can't figure out what is the problem. Can somebody help me?

 
Old June 2nd, 2005, 12:12 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

use
Code:
Due_Date  = new DateTime(DueYear, DueMonth, DueDay)

Regards
Ganesh
 
Old June 3rd, 2005, 08:54 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

change sql = "SELECT User_id, Title, Due_Date FROM [BookLoan_Record] WHERE User_id=@User_id, Title= @Title And Due_Date=@Due_Date"

to: sql = "SELECT User_id, Title, Due_Date FROM [BookLoan_Record] WHERE User_id=@User_id AND Title= @Title And Due_Date=@Due_Date"







Similar Threads
Thread Thread Starter Forum Replies Last Post
dropdownlist sumith ASP.NET 1.0 and 1.1 Professional 1 February 23rd, 2007 09:11 AM
DropdownList Venkatesan ASP.NET 1.0 and 1.1 Basics 1 December 11th, 2006 11:03 AM
how to get value from dropdownlist vandat ASP.NET 1.0 and 1.1 Basics 3 November 28th, 2005 12:47 AM
DropDownList chiraagb VS.NET 2002/2003 5 June 15th, 2004 03:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.