i can able to search with id and mobno
but i also want to search with name i unable to do it when i search with name it showing conversion error bcus it is directly executing
this condition showing conversion error how can i achieve it..
private void BindGrid()
{
int flag;
SqlCommand cmd = new SqlCommand("sp_GridVS", con);
cmd.CommandType = CommandType.StoredProcedure;
if (TextBox3.Text != "")
{
cmd.Parameters.AddWithValue("@mobileno", Convert.ToInt64(TextBox3.Text));
cmd.Parameters.AddWithValue("@id", Convert.ToInt64(TextBox3.Text));
cmd.Parameters.AddWithValue("@flag", 1);
}
else if (TextBox3.Text == "")
{
cmd.Parameters.AddWithValue("@mobileno","");
cmd.Parameters.AddWithValue("@id", 0);
cmd.Parameters.AddWithValue("@flag", 0);
}
DataTable dt = new DataTable();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
This is my sp
CREATE procedure sp_GridVS
@flag int,@id bigint,@mobileno bigint
as begin
if(@flag=1)
begin
select * from gridview where mobileno=@mobileno or id=@id
end
if(@flag=0)
begin
select * from gridview
end
end
This is for seach button
protected void Button2_Click(object sender, EventArgs e)
{
if (TextBox3.Text == "")
{
Response.Write("");
BindGrid();
}
BindGrid();
}
Naimish MakwanaPosted Feb 27, 2023, 11:05 AM
Try below sp
Jaya PrakashPosted Feb 28, 2023, 4:35 AM
Jaya PrakashPosted Feb 28, 2023, 4:03 AM
Jaya PrakashPosted Feb 27, 2023, 11:03 AM
Error sir
Naimish MakwanaPosted Feb 27, 2023, 10:56 AM
Hello Jaya,
I would suggest you to change your sp and code as below and try.
Then change you code to
Thanks
Naimish Makwana
Jaya PrakashPosted Feb 27, 2023, 10:42 AM
i passed id and mobno after that i changed my sp to @flag =2 select * from gridview where name=@name
added few line asp but when i pass name as param it is not showing any values throwing an error conversion problem
i think its taking only id or mobile for this how can i make this textbox works for int type and string type
Naimish MakwanaPosted Feb 27, 2023, 10:32 AM
What value you are passing in TextBox3.Text? It seems it's not valid long type.