I have a form that when I select a column name from a ComboBox, and type in a text box it filters and displays the searched criteria in the DataGridView. When I search for "Reference" which is an int data type, which is also identity, and primary key. I get the error message :
"Cannot perform 'Like' operation on System.Int32 and System.String."
My code is
DataTable dt;
private void searchForm_Load(object sender, EventArgs e)
{
SqlCeConnection con = new SqlCeConnection(#"Data Source=|DataDirectory|\LWADataBase.sdf;");
SqlCeDataAdapter sda = new SqlCeDataAdapter("select * from customersTBL", con);
dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
comboSearch.Items.Add("[Reference]");
comboSearch.Items.Add("[First Name]");
comboSearch.Items.Add("[Surename]");
comboSearch.Items.Add("[Address Line 1]");
comboSearch.Items.Add("[Address Line 2]");
comboSearch.Items.Add("[County]");
comboSearch.Items.Add("[Post Code]");
comboSearch.Items.Add("[Contact Number]");
comboSearch.Items.Add("[Email Address]");
}
private void searchTxt_TextChanged(object sender, EventArgs e)
{
if (comboSearch.SelectedItem == null)
{
searchTxt.ReadOnly = true;
MessageBox.Show("Please select a search criteria");
}
else
{
searchTxt.ReadOnly = false;
DataView dv = new DataView(dt);
dv.RowFilter = "" + comboSearch.Text.Trim() + "like '%" + searchTxt.Text.Trim() + "%'";
dataGridView1.DataSource = dv;
}
}
Convert the number to a string inside the filter:
dv.RowFilter = string.Format("CONVERT({0}, System.String) like '%{1}%'",
comboSearch.Text.Trim(), searchTxt.Text.Trim());
Try this perhaps?
dv.RowFilter = "'%" + comboSearch.Text.Trim() + "%' like '%" + searchTxt.Text.Trim() + "%'";
It may just be a missing quotation, because the query reads as
" 123 like '%123%' "
the code tried to search from gridview (devexpress)..
DataRow[] dr = dt.Select("invoiceId ='" + Convert.ToInt32(gridView1.GetRowCellValue(id, "invoiceId")) + "' AND '%" + Convert.ToDouble(gridView1.GetRowCellValue(id, "Amount_Paid")) + "%' LIKE '%" + Convert.ToDouble(gridView1.GetRowCellValue(id, "Amount")) + "%' ");
if (dr.Length > 0)
{
MessageBox.Show("already paid");
}
Related
I have an aspx page that contains an <asp:Gridview> and displays data from a database.
On the header of the Gridview, I placed a TextBox on each column that can be used to search data from Gridview after pressing Enter. So after hitting enter, it will rebind the gridview, then the searched data will be displayed. Works fine but the text inserted on textbox disappears.
I don't want the text to disappear after rebinding the gridview. So that 'the user can continue on inserting text on the other textbox, and the gridview can display a more specific data.'
Is this possible? or is there any alternatives to achieve my goal?
EDIT
Here's my code:
Page_Load
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["TestCS"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PopulateData();
onSearch();
}
}
Search Event On_Click
protected void btnFilter_Click(object sender, EventArgs e)
{
TextBox tbDelegate = (TextBox)TraineeGrid.HeaderRow.Cells[3].FindControl("newDelegate");
TextBox tbRankPos = (TextBox)TraineeGrid.HeaderRow.Cells[4].FindControl("newRankPos");
TextBox tbCompany = (TextBox)TraineeGrid.HeaderRow.Cells[5].FindControl("newCompany");
TextBox tbCourse = (TextBox)TraineeGrid.HeaderRow.Cells[6].FindControl("newCourse");
TextBox tbCenter = (TextBox)TraineeGrid.HeaderRow.Cells[7].FindControl("newCenter");
TextBox tbInstructor = (TextBox)TraineeGrid.HeaderRow.Cells[8].FindControl("newInstructor");
TextBox tbSdate = (TextBox)TraineeGrid.HeaderRow.Cells[9].FindControl("newStartDate");
TextBox tbEdate = (TextBox)TraineeGrid.HeaderRow.Cells[10].FindControl("newEndDate");
DropDownList tbCissued = (DropDownList)TraineeGrid.HeaderRow.Cells[11].FindControl("newCertIssued");
TextBox tbCnumber = (TextBox)TraineeGrid.HeaderRow.Cells[12].FindControl("newCertNumber");
TextBox tbRemark = (TextBox)TraineeGrid.HeaderRow.Cells[13].FindControl("newRemark");
DataTable dt = new DataTable();
using (con)
{
string sql = "select ID, Delegate, RankPos, Company, CourseTitle, "+
"TrainingCenter, Instructor, convert(varchar(10), " +
"StartDate, 101) as [StartDate], convert(varchar(10), "+
"EndDate, 101) as [EndDate], CertIssued, CertNumber, "+
"Remarks from Trainees ";
if (tbDelegate.Text != string.Empty)
{
HasWhereClause = true;
sql+= "where Delegate LIKE '%" + tbDelegate.Text + "%'";
}
if (tbRankPos.Text != string.Empty)
{
if (HasWhereClause)
{
sql += "and RankPos LIKE '%" + tbRankPos.Text + "%'";
}
else
{
HasWhereClause = true;
sql += "where RankPos LIKE '%" + tbRankPos.Text + "%'";
}
}
if (tbCompany.Text != string.Empty)
{
if (HasWhereClause)
{
sql += "and Company LIKE '%" + tbCompany.Text + "%'";
}
else
{
HasWhereClause = true;
sql += "where Company LIKE '%" + tbCompany.Text + "%'";
}
}
if (tbCourse.Text != string.Empty)
{
if (HasWhereClause)
{
sql += "and CourseTitle LIKE '%" + tbCourse.Text + "%'";
}
else
{
HasWhereClause = true;
sql += "where CourseTitle LIKE '%" + tbCourse.Text + "%'";
}
}
if (tbCenter.Text != String.Empty)
{
if (HasWhereClause)
{
sql += "and TrainingCenter LIKE'%" + tbCenter.Text + "%'";
}
else
{
HasWhereClause = true;
sql += "where TrainingCenter LIKE'%" + tbCenter.Text + "%'";
}
}
if (tbInstructor.Text != String.Empty)
{
if (HasWhereClause)
{
sql += "and Instructor LIKE '%" + tbInstructor.Text + "%'";
}
else
{
HasWhereClause = true;
sql += "where Instructor LIKE '%" + tbInstructor.Text + "%'";
}
}
if (tbSdate.Text != String.Empty)
{
if (HasWhereClause)
{
sql += "and StartDate LIKE '%" + tbSdate.Text + "%'";
}
else
{
HasWhereClause = true;
sql += "where StartDate LIKE '%" + tbSdate.Text + "%'";
}
}
if (tbEdate.Text != String.Empty)
{
if (HasWhereClause)
{
sql += "and EndDate LIKE '%" + tbEdate.Text + "%'";
}
else
{
HasWhereClause = true;
sql += "where EndDate LIKE '%" + tbEdate.Text + "%'";
}
}
if (tbCissued.SelectedIndex != 0)
{
if (HasWhereClause)
{
sql += "and CertIssued LIKE '%" + tbCissued.SelectedValue + "%'";
}
else
{
HasWhereClause = true;
sql += "where CertIssued LIKE '%" + tbCissued.SelectedValue + "%'";
}
}
if (tbRemark.Text != String.Empty)
{
if (HasWhereClause)
{
sql += "and Remarks LIKE '%" + tbCissued.Text + "%'";
}
else
{
HasWhereClause = true;
sql += "where Remarks LIKE '%" + tbCissued.Text + "%'";
}
}
using (SqlCommand cmd = new SqlCommand(sql, con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
}
if (dt.Rows.Count > 0)
{
TraineeGrid.DataSource = dt;
TraineeGrid.DataBind();
}
else if (dt.Rows.Count == 0)
{
dt.Rows.Add(dt.NewRow());
TraineeGrid.DataSource = dt;
TraineeGrid.DataBind();
TraineeGrid.Rows[0].Cells.Clear();
TraineeGrid.Rows[0].Cells.Add(new TableCell());
TraineeGrid.Rows[0].Cells[0].ColumnSpan = dt.Columns.Count;
TraineeGrid.Rows[0].Cells[0].Text = "No Data Found";
TraineeGrid.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
}
}
DataBind Function
private void PopulateData()
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["TestCS"].ConnectionString))
{
string sql = "select ID, Delegate, RankPos, Company, CourseTitle, TrainingCenter, Instructor, convert(varchar(10), " +
"StartDate, 101) as [StartDate], convert(varchar(10), EndDate, 101) as [EndDate], CertIssued, CertNumber, Remarks " +
"from Trainees Order By ID Asc";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
}
if (dt.Rows.Count > 0)
{
TraineeGrid.DataSource = dt;
TraineeGrid.DataBind();
}
else
{
dt.Rows.Add(dt.NewRow());
TraineeGrid.DataSource = dt;
TraineeGrid.DataBind();
TraineeGrid.Rows[0].Cells.Clear();
TraineeGrid.Rows[0].Cells.Add(new TableCell());
TraineeGrid.Rows[0].Cells[0].ColumnSpan = dt.Columns.Count;
TraineeGrid.Rows[0].Cells[0].Text = "No Data Found";
TraineeGrid.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
}
}
OnSearch Function
private void onSearch()
{
Button btnFilter = (Button)TraineeGrid.HeaderRow.Cells[2].FindControl("gvFilter");
TextBox tbDelegate = (TextBox)TraineeGrid.HeaderRow.Cells[3].FindControl("newDelegate");
TextBox tbRankPos = (TextBox)TraineeGrid.HeaderRow.Cells[4].FindControl("newRankPos");
TextBox tbCompany = (TextBox)TraineeGrid.HeaderRow.Cells[5].FindControl("newCompany");
TextBox tbCourse = (TextBox)TraineeGrid.HeaderRow.Cells[6].FindControl("newCourse");
TextBox tbCenter = (TextBox)TraineeGrid.HeaderRow.Cells[7].FindControl("newCenter");
TextBox tbInstructor = (TextBox)TraineeGrid.HeaderRow.Cells[8].FindControl("newInstructor");
TextBox tbSdate = (TextBox)TraineeGrid.HeaderRow.Cells[9].FindControl("newStartDate");
TextBox tbEdate = (TextBox)TraineeGrid.HeaderRow.Cells[10].FindControl("newEndDate");
DropDownList tbCissued = (DropDownList)TraineeGrid.HeaderRow.Cells[11].FindControl("newCertIssued");
TextBox tbCnumber = (TextBox)TraineeGrid.HeaderRow.Cells[12].FindControl("newCertNumber");
TextBox tbRemark = (TextBox)TraineeGrid.HeaderRow.Cells[13].FindControl("newRemark");
tbDelegate.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbRankPos.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbCompany.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbCourse.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbCenter.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbInstructor.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbSdate.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbEdate.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbCissued.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbCnumber.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
tbRemark.Attributes.Add("OnKeyPress", "return controlEnter('" + btnFilter.ClientID + "',event)");
}
On your search button click:
protected void btnSearch_Click(object sender, EventArgs e)
{
//this code should be executed before any other code to ensure it is executed.
ViewState["Values"] += TextBox1.Text;
}
On your gridview row data bound method (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx):
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
TextBox t = (TextBox) e.Row.FindControl("TextBox1");
t.Text = ViewState["Values"].ToString();
}
}
Please read up on how to create a rowdatabound method if it doesn't exist
I want to sort my listbox using combobox,
the combobox will include A-Z and Z-A , so how can I do it and let it work ?
some of my code for the listbox ,lst_OrderName is the one i want to sort.
private void AllorderBySearch()
{
using (connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter("select* from Tbl_order WHERE CustomerNo = '" + txt_CustomerNo.Text + "' And OrderName LIKE '%" + txt_OrderNo.Text + "%' AND OrderName LIKE '%" + txt_OrderNo.Text + "%' AND OrderName LIKE '%" + txt_OrderNo.Text + "%' AND Date between '" + dateTimePicker1.Text + " 00:00:00.000' AND '" + dateTimePicker1.Text + " 23:59:59.999'; ", connection))
{
DataTable Tbl_order = new DataTable();
connection.Open(); //opens the connection
adapter.Fill(Tbl_order);
connection.Close(); //Closes the connection
lst_CustomerNo.DataSource = Tbl_order; //assigns a datasource
lst_CustomerNo.DisplayMember = "CustomerNo"; //assigns display
lst_CustomerNo.ValueMember = "CustomerNo";
lst_OrderName.DataSource = Tbl_order;
lst_OrderName.DisplayMember = "OrderName";
lst_OrderName.ValueMember = "OrderName";
lst_Quantity.DataSource = Tbl_order;
lst_Quantity.DisplayMember = "Quantity";
lst_Quantity.ValueMember = "Quantity";
lst_Price.DataSource = Tbl_order;
lst_Price.DisplayMember = "Price";
lst_Price.ValueMember = "Price";
lst_datetime.DataSource = Tbl_order;
lst_datetime.DisplayMember = "Date";
lst_datetime.ValueMember = "Date";
}
}
I created combobox but i didn't do anything in it yet cuse I dunno how to make it by the way i want . could you help me plz?
you must use a temp object for sorting like bubble sort
As you are using a DataTable as the data source, the following should work:
private void cmbSort_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dt = lst_CustomerNo.DataSource as DataTable;
if(cmbSort.SelectedItem == "A-Z")
dt.DefaultView.Sort = "OrderName ASC";
else
dt.DefaultView.Sort = "OrderName DESC";
}
Attach the above event to your combobox SelectedIndexChanged action..
I have problem when i try to filter data from datagridview. I try to filter datetime field using LIKE and % wilcard. When i assign value in textBoxEdit like this 12-01 or just put 1 am geting:
Does i not format and escape good this query string or is inposible to assign integer value to wilcard? Or maybe any other reson for this sintax error.
Another queries work fine just here i have problem:
sql = "SELECT * FROM grupe_artikala WHERE CONVERT(VARCHAR, created, 120) LIKE '" + searchTextBoxNaziv.Text + "%'";
Check my full code:
private void searchTextBoxNaziv_TextChanged(object sender, EventArgs e)
{
String selectedColumn = filterSearchCombo.Text;
String sql = "";
if(selectedColumn == "ID" && searchTextBoxNaziv.Text is string)
{
sql = "SELECT * FROM grupe_artikala WHERE id LIKE '%" + searchTextBoxNaziv.Text + "%'";
}
else if(selectedColumn == "Name")
{
sql = "SELECT * FROM grupe_artikala WHERE nameLIKE '%" + searchTextBoxNaziv.Text + "%'";
}
else if (selectedColumn == "Descr")
{
sql = "SELECT * FROM grupe_artikala WHERE desc LIKE '%" + searchTextBoxNaziv.Text + "%'";
}
else if (selectedColumn == "Created")
{
sql = "SELECT * FROM grupe_artikala WHERE CONVERT(VARCHAR, created, 120) LIKE '" + searchTextBoxNaziv.Text + "%'";
}
else
{
sql = "SELECT * FROM grupe_artikala";
}
GetData(sql);
}
Update:
private void GetData(string sql)
{
using (conn = new MySqlConnection(Properties.Settings.Default.ConnectionString))
{
try
{
conn.Open();
adapter = new MySqlDataAdapter(sql, conn);
dt = new DataTable();
bs = new BindingSource();
adapter.Fill(dt);
bs = new BindingSource();
bs.DataSource = dt;
dataGridView1.DataSource = bs;
bindingNavigator1.BindingSource = bs;
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
}
you don't need to convert date to varchar
SELECT * FROM grupe_artikala WHERE CONVERT(VARCHAR, created, 120) LIKE '" + searchTextBoxNaziv.Text + "%'
instead use below query
SELECT * FROM grupe_artikala WHERE created LIKE '" + searchTextBoxNaziv.Text + "%'
It will simply search data according to where condition.
This is not the problem that you stated but there needs to be a space between name and LIKE in
"SELECT * FROM grupe_artikala WHERE nameLIKE '%" + searchTextBoxNaziv.Text + "%'", because that query won't work.
As for your problem, since you are saying you are using mysql - you have a syntax error in your CONVERT it should be CONVERT(created, VARCHAR(120))
Try this.
SELECT * FROM grupe_artikala WHERE CONVERT(VARCHAR(10), created, 120) LIKE '" + searchTextBoxNaziv.Text + "%'";
Instead of
sql = "SELECT * FROM grupe_artikala WHERE CONVERT(VARCHAR, created, 120) LIKE '" + searchTextBoxNaziv.Text + "%'";
refer this link.
convert convert-datetime-to-varchar
https://technet.microsoft.com/en-us/library/ms187928(v=sql.105).aspx
OR
TRY this,
sql = "SELECT * FROM grupe_artikala WHERE LEFT(CONVERT(VARCHAR, created, 120), 10)
LIKE '" + searchTextBoxNaziv.Text + "%'";
private void searchTextBoxNaziv_TextChanged(object sender, EventArgs e)
{
String selectedColumn = filterSearchCombo.Text;
String sql = "";
if (searchTextBoxNaziv.Text.length > 0)
{
SqlCommand com = conn.CreateCommand();
com.Parameters.AddWithValue("#search", searchTextBoxNaziv.Text.ToLower());
switch (selectedColumn)
{
case "ID":
com.Parameters.AddWithValue("#searchItem", "ID");
break;
case "Name":
com.Parameters.AddWithValue("#searchItem", "Name");
break;
case "Descr":
com.Parameters.AddWithValue("#searchItem", "Desc");
break;
case "Created":
com.Parameters.AddWithValue("#searchItem", whateverCreatedIs);
break;
}
com.CommandText = "select * from grupe_artikala where lcase(#searchItem) like %#search%";
//execute SELECT
}
}
UPDATE: I'm really sorry, but I don't have MySQL installed and have to work off memory (no Intellisense). I think this will get you there or close to it. Hope it helps!
private void searchTextBoxNaziv_TextChanged(object sender, EventArgs e)
{
String selectedColumn = filterSearchCombo.Text;
String sql = "";
conn = new MySqlConnection(Properties.Settings.Default.ConnectionString);
com = new MySqlCommand("select * from grupe_artikala where lcase(#searchItem) like %#search%", conn);
if (searchTextBoxNaziv.Text.length > 0)
{
com.Parameters.AddWithValue("#search", searchTextBoxNaziv.Text.ToLower());
switch (selectedColumn)
{
case "ID":
com.Parameters.AddWithValue("#searchItem", "ID");
break;
case "Name":
com.Parameters.AddWithValue("#searchItem", "Name");
break;
case "Descr":
com.Parameters.AddWithValue("#searchItem", "Desc");
break;
case "Created":
com.Parameters.AddWithValue("#searchItem", whateverCreatedIs);
break;
}
GetData(conn, com);
}
}
private void GetData(MySqlConnection conn, MySqlCommand com)
{
try
{
conn.Open();
MySqlDataAdapter da = new MySqlDataAdapter();
da.SelectCommand = com;
dt = new DataTable();
bs = new BindingSource();
da.Fill(dt);
bs = new BindingSource();
bs.DataSource = dt;
dataGridView1.DataSource = bs;
bindingNavigator1.BindingSource = bs;
conn.Close();
conn.Dispose();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
Mabuhay!
What is the most efficient or more convenient way to do this.
I have a select query and put it on a datagridview base on my filter. It has 5 columns. I want to know if Column CA from that Datagridview already exist on Table 2 which is on Column 3?
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=db;User ID=sa;Password=pw");
// DateTime dt = new DateTime();
//dt = DateTime.Now.ToString();
SqlDataAdapter sda = new SqlDataAdapter("SELECT max(PurchaseOrder.POTitle) as Description,sum(PurchaseOrderEntry.Price *PurchaseOrderEntry.QuantityOrdered) as Amount, max(PurchaseOrder.PONumber)as PONumber, " +
" max(PurchaseOrderEntry.OrderNumber) as BoxCount, max(PurchaseOrderEntry.OrderNumber) as PLC,max(PurchaseOrderEntry.OrderNumber) as Branch, max(PurchaseOrderEntry.OrderNumber) as PreparedBy, max(PurchaseOrderEntry.OrderNumber) as CheckedBy " +
" FROM PurchaseOrder LEFT OUTER JOIN" +
" PurchaseOrderEntry ON PurchaseOrder.ID = PurchaseOrderEntry.PurchaseOrderID" +
" WHERE (PurchaseOrder.Remarks like '%" + tanggapan.Text + "%') AND (PurchaseOrder.DateCreated BETWEEN '" + dateTimePicker1.Text + "' AND '" + dateTimePicker2.Text + "' and PurchaseOrder.OtherStoreID = '" + branch.Text + "') Group By PurchaseOrder.PONumber", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
This show my query filter. Any tip on how to do if PurchaseOrderEntry.OrderNumber already exist on my records so I can manage which one repeats.
Thank you!
Chris
I added this code now on my works and it is working now.
DataTable dt = new DataTable();
dt.Clear();
dt.Reset();
con.Close();
adaptors1.SelectCommand = con.CreateCommand();
adaptors1.SelectCommand.CommandText = "Select TOP 1 [ponumber],[clref] from [ISSPandayan].[dbo].[" + branch.Text + "] where [ponumber] = '" + dr.Cells["ponumber"].Value + "' ORDER BY [clref] ASC";
adaptors1.Fill(dt);
// select query para malam kung existing ponumber
if (dt.Rows.Count == 1)
{
adaptorss.InsertCommand.Parameters.Add("#already", SqlDbType.VarChar).Value = dt.Rows[0][1].ToString();
}
else
{
adaptorss.InsertCommand.Parameters.Add("#already", SqlDbType.VarChar).Value = " ";
}
//adaptorss.InsertCommand.Parameters.Add("#already", SqlDbType.VarChar).Value = "";
//MessageBox.Show(Convert.ToString(dr.Cells["description"].Value));
con.Close();
con.Open();
adaptorss.InsertCommand.ExecuteNonQuery();
adaptorss.InsertCommand.Parameters.Clear();
I have this problem, i search the DB and return results which i turn into links and print them but with the way i have chosen "Response.Write();" i get the results printed at the upper left corner, which sucks cause it messes up my whole page... :(
Is there a way i can print at a specific location (under the search bar preferably) and keep the results as links ?
Thanks in advance!
protected void Button1_Click1(object sender, EventArgs e)
{
DataTable PassRecord = new DataTable();
String str = "select First_Name,Email_Account,Surname,id from ID where (First_Name like '%'+ #search +'%' ) OR (Surname like '%'+ #search +'%') OR (Email_Account like '%'+ #search +'%')";
SqlCommand Srch = new SqlCommand(str, con);
Srch.Parameters.Add("#search", SqlDbType.NVarChar).Value = TextBox1.Text;
if (TextBox1.Text != "")
{
con.Open();
Srch.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = Srch;
DataTable dt = new DataTable();
DataTable dtResult = new DataTable();
da.Fill(dt);
PID = (int)(Session["id"]);
int SaveTheFirst = PID;
foreach (DataRow dr in dt.Rows)
{
PID2 = dr["id"].ToString() ;
if (PID.ToString() != PID2 )
{
counter++;
var field = "<a href='" + Page.ResolveUrl("~/PageView.aspx?Email=" + dr["id"].ToString()) + "'>" + (dr["First_Name"] + "").ToString() + "</a>";
Response.Write(field);
HttpContext context = HttpContext.Current;
Response.Write("<br/>");
}
}
con.Close();
}
else
{
string display = " Not Valid Search Criteria!";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);
}
}