This is my column in db
mobno bigint
9491992426
9491992426
9491992426
9491992426
9491992426
9491992426
This is my SP
create procedure sp_SearchBy
@mobno bigint
as begin
select * from form where mobno like '%' + @mobno + '%'
end
i want to search with mobile number in grid view . when i searched with name i got the result but when i search with mobile no it is showing input string was in invlid format
i have taken bigint for mobno in db i want to search with mobile number pls help me
This is my webform.aspx.cs
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
DisplayInfo();
}
if (!this.IsPostBack)
{
this.BindGrid();
}
}
void DisplayInfo()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
string query = "select * from form";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
this.BindGrid();
}
private void BindGrid() (This Is for Searching )
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
SqlCommand cmd = new SqlCommand("sp_SearchByme", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@mobno",Convert.ToInt32(TextBox7.Text)); //(I got the error here conversion problem)
//(Input string was not in a correct format)
DataTable dt = new DataTable();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindGrid();
}
}
Naimish MakwanaPosted Feb 17, 2023, 4:05 AM
Hello Jaya,
Try below - Change
To
NOTE: Please check if your string has any white space or not. If it contains space, then will throw the error.
Thanks
Naimish Makwana
Naimish MakwanaPosted Feb 17, 2023, 5:34 AM
Hello Jaya,
Put debug point on line no 67. You shared screenshot below.
Once debug point reach on 67. Mouse over on Textbox6.Text it will show you the value of the textbox.
Thanks
Naimish Makwana
Jaya PrakashPosted Feb 17, 2023, 5:27 AM
Hi Naimish Sir,
i about to enter mobile number in textbox6.text. when i debug the it is not showing the aspx page its directly thows an error
input string was not in a correct format
Naimish MakwanaPosted Feb 17, 2023, 4:21 AM
Hello jaya,
What is the value of Texbox6.Text?
NOTE: Please check if your string has any white space or not. If it contains space, then will throw the error.
Thanks
Naimish Makwana
Jaya PrakashPosted Feb 17, 2023, 4:19 AM
Same Error Sir Pls Help me out in my database i took bigint for mobno
Amit MohantyPosted Feb 17, 2023, 4:12 AM
Your TextBox7 value must be numeric. Please chaek your value first. or you may try Tuhin Paul's solutions.
Jaya PrakashPosted Feb 17, 2023, 3:56 AM
not working sir still the error same
Tuhin PaulPosted Feb 16, 2023, 7:04 PM
The error "Input string was not in a correct format" occurs because you are trying to convert a string to an integer using the Convert.ToInt32 method, but the string is not in the correct format.
Since the mobno field in your database is defined as a bigint, you should use the Convert.ToInt64 method to convert the string to a long (which is the equivalent of a bigint in C#). Here is the modified code for the BindGrid method:
In the modified code, I have used the long.TryParse method to convert the string to a long value. This method returns a boolean value that indicates whether the conversion was successful or not. If the conversion is successful, the mobileNo variable will contain the converted value, and you can use it as the parameter value for the stored procedure. If the conversion fails, you can handle the invalid input appropriately (for example, by displaying an error message to the user).
Bro hope this helps, please let me know if it works for you.