• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

SQL Command will not work

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
bhorlings
Asked:
bhorlings
  • 2
1 Solution
 
raterusCommented:
It would really help to mention what problem you are having / error message you are receiving!
0
 
bhorlingsAuthor Commented:
My apologies. When I click submit everything looks like the query is executing and performing the insert command but it does not.
0
 
raterusCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now