Solved

SQL Command will not work

Posted on 2008-06-26
3
404 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

635 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