TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Krishna
NA
37
9.4k
Databinding
Mar 20 2015 12:48 AM
i would like to add the retrieved data to the grid view but its displaying error
Must declare the scalar variable "@x".
.cs
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
//var x = Request.QueryString ;
con.Open();
string x = Request.QueryString["Name"];
string selectString = "select * from products where keyword like @x";
SqlCommand cmd = new SqlCommand(selectString, con);
SqlDataAdapter da = new SqlDataAdapter("select * from products where keyword like @x", con);
cmd.Parameters.AddWithValue("@x", "%" + x + "%");
SqlDataReader reader = cmd.ExecuteReader();
List<product> values = new List<product>();
da.Fill(ds,x);
GridView1.DataSource = ds;
GridView1.DataBind();
try
{
while (reader.Read())
{
values.Add(new product()
{
keyword = reader.GetString(reader.GetOrdinal("keyword"))
});
}
reader.Close();
}
catch (Exception ex)
{
}
}
public class product
{
public string keyword { get; set; }
}
}
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="output.aspx.cs" Inherits="output" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" method="POST" runat="server">
<br />
<a href ="http://localhost:49369/Home.aspx">Home</a>
<a href =" http://localhost:49369/login.aspx">Login</a>
<br />
<br />
<img alt="" src="Images/aa2.png" style="height: 237px; width: 875px" />;
<h3>Comparable Entites in Lexical Patterns </h3>
<p>
</p>
<p>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</p>
<br />
<br />
</form>
</body>
</html>
Reply
Answers (
5
)
stable webform1 after redirect to webform2
stored procedure