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
saroj bhattacharya
NA
0
42.9k
how to solved ?
Jul 16 2015 2:47 AM
how solved this error the error is bellow
ERROR:
Unclosed quotation mark after the character string 'Cambridge'.
Incorrect syntax near 'Cambridge'.
my code is bellow
search.aspx.cs code
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 csvfileupload2
{
public partial class search : System.Web.UI.Page
{
string str = "Data Source=ANIRUDDHA-PC;Initial Catalog=sark;Integrated Security=True";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
String strQuery = "SELECT distinct (city) FROM profilesrr";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
try
{
con.Open();
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "city";
DropDownList1.DataValueField = "city";
DropDownList1.DataBind();
// DropDownList2.SelectedIndex = 1;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
String strQuery = "SELECT distinct (city) FROM profilesrr";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
try
{
con.Open();
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "city";
DropDownList1.DataValueField = "city";
DropDownList1.DataBind();
// DropDownList2.SelectedIndex = 1;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = "Data Source=ANIRUDDHA-PC;Initial Catalog=sark;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("select * from profilesrr where city = '" + DropDownList1.SelectedValue + "", con);
SqlDataAdapter Adpt = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
Adpt.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
and search.aspx code are bellow
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="search.aspx.cs" Inherits="csvfileupload2.search" %>
<!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 id="Head1" runat="server">
<title></title>
</head>
<body style="height: 415px">
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="select city"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="search" />
<br />
<br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
please help me
Reply
Answers (
5
)
Asp. Net Web Application
Trace Performance of application