Question ASP.NET ODBC Query with String parameter

Status
Not open for further replies.

Hytek

New member
Joined
Mar 23, 2016
Messages
1
Programming Experience
Beginner
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:

publicpartialclassIncidents:System.Web.UI.Page
{
protectedvoidPage_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:

<%@PageLanguage="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">

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
<linkhref="Styles.css"rel="stylesheet"type="text/css"/>
</head>
<body>
<formid="form1"runat="server">
<div>
<h1>Incidents</h1>
<p>
<asp:GridViewID="GridView1"runat="server"CssClass="DataWebControlStyle">
<HeaderStyleCssClass="HeaderStyle"/>
<AlternatingRowStyleCssClass="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)?
 
Status
Not open for further replies.
Top Bottom