I am using a tableadapter to query a database using ODBC. The query is being created by the VS2015 Query Builder. If I make the SQL statement with a variable parameter then the result comes back blank. If I replace the parameter (the question-mark) with a hardcoded parameter then the result comes back fine. Below is my code for the example where the result comes back blank.
SQL Statement:
SELECT HPD_Help_Desk.Incident_Number, HPD_Help_Desk.Assigned_Group
FROM HPD_Help_Desk HPD_Help_Desk
WHERE (HPD_Help_Desk.Incident_Number > 'INC100000230000')
AND (HPD_Help_Desk.Assigned_Support_Organization LIKE '%?%')
I have set the parameter member details using the Parameter Collection Editor and set DbType to String, which defaults the ProviderType to NVarChar. The rest of the fields I have left as is.
Default.aspx.cs:
public partial class Incidents : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string s = "Copenhagen POD";
HPD_Help_DeskTableAdapter incidentsAdapter = new HPD_Help_DeskTableAdapter();
GridView1.DataSource = incidentsAdapter.GetIncidentsByAssigned_Support_Organization(s);
GridView1.DataBind();
}
}
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" inherits="Incidents" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<link href="Styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Incidents</h1>
<p>
<asp:GridView ID="GridView1" runat="server" CssClass="DataWebControlStyle">
<HeaderStyle CssClass="HeaderStyle" />
<AlternatingRowStyle CssClass="AlternatingRowStyle" />
</asp:GridView>
</p>
</div>
</form>
</body>
</html>
So what am I missing? What should I change to make the SQL statement work properly using the parameter I specify in Default.aspx.cs (Copenhagen POD)?
... LIKE ?)and your parameter value should be%<yourvalue>%. I don't think ODBC takes a question mark inside'..'as parameter placeholder.DbTypeproperty of the parameter toDbType.String(which actually should be default, but anyway).