Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using ASP.net framework + SQL. So anyways, I'm trying to retrieve a data it tells me i have an incorrect syntax near '.'. which I do not understand. It says the source of my problem is at line 81 which is
Quote:
SqlDataReader dr = com.ExecuteReader();


Below is my code.
Edit_DVO.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Administrator/Operations.master" 
    AutoEventWireup="true" CodeFile="Edit_DVO.aspx.cs" Inherits="OperationsDepartment.Operations.Edit_DVO" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    Edit DVO Details</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        View User #<asp:Literal ID="ltID" runat="server" />
                    </div>
                    <form role="form" id="form1">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label>
                                        Customer Last Name</label>
                                    <asp:TextBox ID="txtLN" runat="server" class="form-control" placeholder="Last Name"
                                        required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Customer First Name</label>
                                    <asp:TextBox ID="txtFN" runat="server" class="form-control" placeholder="First Name"
                                        required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Dealer Name</label>
                                    <asp:TextBox ID="txtDN" runat ="server" class="form-control" placeholder="Name"
                                        required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Quantity</label>
                                    <asp:TextBox ID="txtQ" runat="server" class="form-control" placeholder="Quantity"
                                        required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Model</label>
                                    <asp:DropDownList ID="ddlMod" runat="server" class="form-control">
                                    </asp:DropDownList>
                                </div>
                               
                                <div class="form-group">
                                    <label>
                                        Quotation Reference No</label>
                                    <asp:TextBox ID="txtQR" runat="server" class="form-control" placeholder="Quotation Reference" required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Total Amount</label>
                                    <asp:TextBox ID="txtTA" runat="server" class="form-control" placeholder="Total Amount"
                                        required />
                                </div>
                                </br>
                            </div>
                            <!-- /.col-lg-6 (nested) -->
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label>
                                        Payment Term</label>
                                    <asp:DropDownList ID="ddlPT" runat="server" class="form-control">
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Target Delivery</label>
                                    <asp:TextBox ID="txtTD" runat="server" class="form-control" placeholder="Target Delivery" required />
                                </div>
                                <div class="form-group">
                                    <label>
                                        Status</label>
                                    <asp:DropDownList ID="ddlStatus" runat="server" Width="200px">
                                        <asp:ListItem Text="Approved" Value="Approved"></asp:ListItem>
                                        <asp:ListItem Text="Pending" Value="Pending"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Received</label>
                                    <asp:DropDownList ID="ddlIR" runat="server">
                                        <asp:ListItem Text="Yes" Value="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="False"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Approved</label>
                                    <asp:DropDownList ID="ddlIA" runat="server">
                                        <asp:ListItem Text="Yes" Value="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="False"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Evaluated</label>
                                    <asp:DropDownList ID="ddlIE" runat="server">
                                        <asp:ListItem Text="Yes" Value="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="False"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                                <div class="form-group">
                                    <label>
                                        Processed</label>
                                    <asp:DropDownList ID="ddlIP" runat="server">
                                        <asp:ListItem Text="Yes" Value="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="False"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                            </div>
                            <!-- /.col-lg-6 (nested) -->
                        </div>
                        <asp:Button ID="btnCancel" runat="server" class="btn btn-default" Text="Cancel" PostBackUrl="~/Operations/DVO_History.aspx"
                            formnovalidate />
                        <asp:Button ID="btnSubmit_Edit" runat="server" class="btn btn-success" Text="Submit Button"
                            OnClick="btnSubmit_Edit_Click" />
                        <!-- /.row (nested) -->
                    </div>
                    </form>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
</asp:Content>


Edit_DVO.asx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace OperationsDepartment.Operations
{
    public partial class Edit_DVO : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(Helper.GetCon());
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null) // record no selected
            {
                int userID = 0;
                bool validDVO_ID = int.TryParse(Request.QueryString["ID"].ToString(), out userID);

                if (validDVO_ID)
                {
                    if (!IsPostBack)
                    {
                        GetModel();
                        GetPaymentTerm();
                        GetInfo(userID);
                    }
                }
                else
                    Response.Redirect("DVO_History.aspx");
            }
            else
                Response.Redirect("DVO_History.aspx"); //change this to main homepage if meron na
        }
    
        protected void btnSubmit_Edit_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "Update DVO SET LastName=@LastName,FirstName=@FirstName,DealerName=@DealerName, " +
                "Qty=@Qty,Model=@ProductID,QuotationRefNo=@QuotationRefNo,TotalAmount=@TotalAmount, " +
                "Term=@PaymentTermID,TargetDelivery=@TargetDelivery,Status=@Status, " +
                "IsReceived=@IsReceived,IsApproved=@IsApproved, IsEvaluated=@IsEvaluated, IsProcessed=@IsProcessed WHERE DVO_ID=@DVO_ID";
            com.Parameters.AddWithValue("LastName", txtLN.Text);
            com.Parameters.AddWithValue("FirstName", txtFN.Text);
            com.Parameters.AddWithValue("DealerName", txtDN.Text);
            com.Parameters.AddWithValue("Qty", txtQ.Text);
            com.Parameters.AddWithValue("ProductID", ddlMod.SelectedValue);
            com.Parameters.AddWithValue("QuotationRefNo", txtQR.Text);
            com.Parameters.AddWithValue("TotalAmount", txtTA.Text);
            com.Parameters.AddWithValue("PaymentTermID", ddlPT.SelectedValue);
            com.Parameters.AddWithValue("TargetDelivery", txtTD.Text);
            com.Parameters.AddWithValue("Status", ddlStatus.SelectedValue);
            com.Parameters.AddWithValue("IsReceived", ddlIR.SelectedValue);
            com.Parameters.AddWithValue("IsApproved", ddlIA.SelectedValue);
            com.Parameters.AddWithValue("IsEvaluated", ddlIE.SelectedValue);
            com.Parameters.AddWithValue("IsProcessed", ddlIP.SelectedValue);
            com.Parameters.AddWithValue("DVO_ID", Request.QueryString["ID"].ToString());
            com.ExecuteNonQuery();
            con.Close();
            Response.Redirect("DVO_History.aspx");
            
        }
        void GetInfo(int ID)
        {
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "SELECT c.LastName, c.FirstName, dt.DealerName, " +
                "d.Qty, p.Model, d.QuotationRefNo, d.TotalAmount, pt.Term, d.TargetDelivery, d.Status " +
                "d.IsReceived, d.IsApproved, d.IsEvaluated, d.IsProcessed " +
                "FROM DVO d " +
                "INNER JOIN Dealer dt ON d.DealerID=dt.DealerID " +
                "INNER JOIN Customer c ON d.CustomerID=c.CustomerID " +
                "INNER JOIN Product p ON d.ProductID=p.ProductID " +
                "INNER JOIN PaymentTerm pt ON d.PaymentTermID=pt.PaymentTermID WHERE DVO_ID=@DVO_ID";
            com.Parameters.AddWithValue("DVO_ID", ID);
            SqlDataReader dr = com.ExecuteReader();
            if (dr.HasRows) //record existing
            {
                while (dr.Read())
                {
                    ddlMod.SelectedValue = dr["Model"].ToString();
                    ltID.Text = dr["DVO_ID"].ToString();
                    ddlStatus.SelectedValue = dr["Status"].ToString();
                    ddlPT.SelectedValue = dr["PaymentTerm"].ToString();
                    ddlIR.SelectedValue = dr["IsReceived"].ToString();
                    ddlIA.SelectedValue = dr["IsApproved"].ToString();
                    ddlIE.SelectedValue = dr["IsEvaluated"].ToString();
                    ddlIP.SelectedValue = dr["IsProcessed"].ToString();
                    txtFN.Text = dr["FirstName"].ToString();
                    txtLN.Text = dr["LastName"].ToString();
                    txtDN.Text = dr["DealerName"].ToString();
                    txtQ.Text = dr["Qty"].ToString();

                    txtQR.Text = dr["QuantityRefNo"].ToString();
                    txtTA.Text = dr["TotalAmount"].ToString();
                    txtTD.Text = dr["TargetDelivery"].ToString();


                }
                con.Close();
            }
            else // not existing
            {
                con.Close();
                Response.Redirect("DVO_History.aspx");

            }
        }


        void GetModel()
        {
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "SELECT ProductID, Model FROM Product";
            SqlDataReader dr = com.ExecuteReader();
            ddlMod.DataSource = dr;
            ddlMod.DataTextField = "Model";
            ddlMod.DataValueField = "ProductID";
            ddlMod.DataBind();
            con.Close();

        }


        void GetPaymentTerm()
        {
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "SELECT PaymentTermID, Term FROM PaymentTerm";
            SqlDataReader dr = com.ExecuteReader();
            ddlPT.DataSource = dr;
            ddlPT.DataTextField = "Term";
            ddlPT.DataValueField = "PaymentTermID";
            ddlPT.DataBind();
            con.Close();

        }




    }
}


What I have tried:

I tried using the same sql command text at my SQL Server and it works. So I do not know where the problem is coming from. I searched the meaning of my problem and it says I'm getting a null object but I know i am not getting any null object.
Posted
Updated 28-May-17 2:24am
Comments
[no name] 28-May-17 6:57am    
Your problem is from you concatenating bits and pieces of your your SQL strings together.
Kornfeld Eliyahu Peter 28-May-17 7:58am    
Where? As I can see OP uses parameterized SQL queries...
[no name] 28-May-17 8:18am    
This is NOT the same code he originally posted.
Kornfeld Eliyahu Peter 28-May-17 8:20am    
...I see - I just was wondering what I have missed :-)

1 solution

A simple syntax error here:
SQL
"d.Qty, p.Model, d.QuotationRefNo, d.TotalAmount, pt.Term, d.TargetDelivery, d.Status " +
                "d.IsReceived, d.IsApproved, d.IsEvaluated, d.IsProcessed " +

You have no comma (,) after d.Status...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900