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>
</div>
<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>
<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>
</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" />
</div>
</form>
</div>
</div>
</div>
</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)
{
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");
}
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)
{
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
{
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.