Solved

SQL Command will not work

Posted on 2008-06-26
3
380 Views
Last Modified: 2013-11-06
I cannot figure out why my command will not work. It appears to me that everything is properly formatted. Can someone take a look at it and give suggestions?
<%@ Page Language="VB" MasterPageFile="~/_m/nonavbars.master" AutoEventWireup="false" CodeFile="jz_trucks.aspx.vb" Inherits="_a_jz_trucks" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cphMain" Runat="Server">

        <h3>Juarez ICT Truck Shipments</h3>

        <h4>Add a new truck shipment</h4>

        Leave Date:&nbsp;<asp:textbox id="txtLveDate" runat="server" tabindex="1"></asp:textbox>&nbsp;

        <asp:imagebutton id="ibtnLveDate" runat="server" imageurl="~/_i/calendar.png" tabindex="2" />

        <asp:requiredfieldvalidator id="reqLveDate" runat="server" controltovalidate="txtLveDate"

            errormessage="*"></asp:requiredfieldvalidator><br />

        Arrive Date:&nbsp;<asp:textbox id="txtArvDate" runat="server" tabindex="3"></asp:textbox>&nbsp;

        <asp:imagebutton id="ibtnArvDate" runat="server" imageurl="~/_i/calendar.png" tabindex="4" />

        <asp:requiredfieldvalidator id="reqArvDate" runat="server" controltovalidate="txtArvDate"

            display="Dynamic" errormessage="*"></asp:requiredfieldvalidator><br />

        Initials:&nbsp;<asp:textbox id="txtInitials" runat="server" maxlength="3" tabindex="5"></asp:textbox>&nbsp;

        <asp:requiredfieldvalidator id="reqInitials" runat="server" controltovalidate="txtInitials"

            display="Dynamic" errormessage="*"></asp:requiredfieldvalidator><br />

        <asp:linkbutton id="lbtnJzTrkSubmit" runat="server" tabindex="6">Submit</asp:linkbutton>&nbsp;

        <asp:linkbutton id="lbtnJzTrkReset" runat="server" tabindex="7" causesvalidation="False">Reset</asp:linkbutton>&nbsp;

    <asp:label id="lblTruckSubmitted" runat="server" forecolor="#00C000" text="Truck shipment successfully submitted."

        visible="False"></asp:label><h4>Future Shipments</h4>

    <asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" cellpadding="4" datasourceid="srcJzTrucks" emptydatatext="There are current no shipments scheduled." forecolor="#333333" gridlines="None">

        <footerstyle backcolor="#990000" font-bold="True" forecolor="White" />

        <rowstyle backcolor="#FFFBD6" forecolor="#333333" />

        <columns>

            <asp:boundfield datafield="leave_date" dataformatstring="(0:d}" headertext="Leaving"

                htmlencode="False" sortexpression="leave_date" />

            <asp:boundfield datafield="arrive_date" dataformatstring="(0:d}" headertext="Arriving"

                htmlencode="False" sortexpression="arrive_date" />

            <asp:boundfield datafield="initials" headertext="Submitted By" sortexpression="initials" />

            <asp:boundfield datafield="submit_date" dataformatstring="(0:d}" headertext="Submitted"

                htmlencodeformatstring="False" sortexpression="submit_date" />

        </columns>

        <pagerstyle backcolor="#FFCC66" forecolor="#333333" horizontalalign="Center" />

        <selectedrowstyle backcolor="#FFCC66" font-bold="True" forecolor="Navy" />

        <headerstyle backcolor="#990000" font-bold="True" forecolor="White" />

        <alternatingrowstyle backcolor="White" />

    </asp:gridview>

    <asp:sqldatasource id="srcJzTrucks" runat="server" connectionstring="<%$ ConnectionStrings:conIntranet %>"

        selectcommand="SELECT leave_date, arrive_date, initials, submit_date FROM jz_truck WHERE (arrive_date > { fn NOW() }) ORDER BY leave_date, arrive_date">

    </asp:sqldatasource>

        <ajaxtoolkit:calendarextender id="calxLveDate" runat="server" popupbuttonid="ibtnLveDate" targetcontrolid="txtLveDate">

        </ajaxtoolkit:calendarextender>

        <ajaxtoolkit:calendarextender id="calxArvDate" runat="server" popupbuttonid="ibtnArvDate" targetcontrolid="txtArvDate">

        </ajaxtoolkit:calendarextender>

        <ajaxtoolkit:textboxwatermarkextender id="wtrLveDate" runat="server" targetcontrolid="txtLveDate" watermarktext="Enter leave date.">

        </ajaxtoolkit:textboxwatermarkextender><ajaxtoolkit:textboxwatermarkextender id="wtrArvDate" runat="server"  watermarktext="Enter arrive date."

            targetcontrolid="txtArvDate">

        </ajaxtoolkit:textboxwatermarkextender>

        <ajaxtoolkit:textboxwatermarkextender id="wtrInitials" runat="server"  watermarktext="Enter initials."

            targetcontrolid="txtInitials">

        </ajaxtoolkit:textboxwatermarkextender>

        <ajaxtoolkit:maskededitextender id="meeLveDate" masktype="Date" mask="99/99/9999" runat="server" targetcontrolid="txtLveDate">

        </ajaxtoolkit:maskededitextender>

        <ajaxtoolkit:maskededitextender id="meeArvDate" masktype="Date" mask="99/99/9999" runat="server" targetcontrolid="txtArvDate">

        </ajaxtoolkit:maskededitextender>

</asp:Content>
 
 

Imports System.IO

Imports System.DateTime

Imports System.Data

Imports System.Data.SqlClient

Imports System.Web.Configuration
 

Partial Class _a_jz_trucks

    Inherits System.Web.UI.Page
 

    Protected Sub lbtnJzTrkReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnJzTrkReset.Click

        Me.txtArvDate.Text = ""

        Me.txtInitials.Text = ""

        Me.txtLveDate.Text = ""

        Me.lblTruckSubmitted.Visible = False

    End Sub
 

    Protected Sub lbtnJzTrkSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnJzTrkSubmit.Click

        Dim dteLve As Date = Me.txtLveDate.Text

        Dim dteArv As Date = Me.txtArvDate.Text

        Dim dteSub As Date = Today.ToString()

        Dim strInitials As String = Me.txtInitials.Text

        Dim connectionString As String = WebConfigurationManager.ConnectionStrings("conIntranet").ConnectionString

        Dim con As New SqlConnection(connectionString)

        Dim cmdJzTruckInsert As New SqlCommand("INSERT jz_truck (leave_date, arrive_date, submit_date, initials) values (@LveDate, @ArvDate, @SubDate, @Initials)", con)

        cmdJzTruckInsert.Parameters.Add("@LveDate", SqlDbType.Date).Value = dteLve

        cmdJzTruckInsert.Parameters.Add("@ArvDate", SqlDbType.Date).Value = dteArv

        cmdJzTruckInsert.Parameters.Add("@SubDate", SqlDbType.Date).Value = dteSub

        cmdJzTruckInsert.Parameters.Add("@Initials", SqlDbType.NVarChar, 50).Value = strInitials

        Try

            con.Open()

            cmdJzTruckInsert.ExecuteNonQuery()

        Catch ex As Exception

        Finally
 

            con.Close()

        End Try

        Me.lblTruckSubmitted.Visible = True

    End Sub

End Class

Open in new window

0
Comment
Question by:bhorlings
  • 2
3 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 21875610
It would really help to mention what problem you are having / error message you are receiving!
0
 
LVL 1

Author Comment

by:bhorlings
ID: 21876244
My apologies. When I click submit everything looks like the query is executing and performing the insert command but it does not.
0
 
LVL 33

Accepted Solution

by:
raterus earned 250 total points
ID: 21876382
You have an empty Catch statement, which is the quickest way to "ignore" errors and never know there is a problem!

rewrite this

        Try
            con.Open()
            cmdJzTruckInsert.ExecuteNonQuery()
        Catch ex As Exception
        Finally
 
            con.Close()
        End Try


to this, and you should see the problem

        Try
            con.Open()
            cmdJzTruckInsert.ExecuteNonQuery()
        Finally
 
            con.Close()
        End Try
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now