i've error in my button control?

Posted by Sudheep.grandhe under C# on 11/14/2011 | Points: 10 | Views : 1392 | Status : [Member] | Replies : 8
Hi,

i have a form like ordersearch and in that one button named like search.after run the application when i was click on the search button it displays the data.without enter the orderno in the specified textbox.

private void btn_search_Click(object sender, EventArgs e)
{
//MessageBox .Show ("");
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("select compname,compaddress,invoiceno,orderno,convert(varchar,ondate,105)as [ondate],convert(varchar,invoicedate,105)as [invoicedate],amountstatus,netamount,netvat,tamount from tbl_report2 where orderno=@orderno", con);
con.Open();
cmd.Parameters.AddWithValue("@orderno", txt_orderno.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
con.Close();
}
else
{
//GridView1.Controls.Clear();
GridView1.DataSource = null;
MessageBox.Show("sorry no data availlable");
}


}

private void txt_orderno_TextChanged(object sender, EventArgs e)
{
GridView1.Controls.Clear();
}

private void OrderSearch_Load(object sender, EventArgs e)
{
//GridView1.Controls.Clear();
//txt_orderno.Focus();
}
}

Best,
Sudheep.



Responses

Posted by: Blessyjees on: 11/14/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

What is your issue. What you want. Do you have any default value in the textbox.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/14/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

If i enter the value in the textbox it has to display the data.without entering any data in textbox and if i made a click on search button it shows the data.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 11/14/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Do you have any default value in the textbox. is orderno mandatory column in table? Can you debug and check the query at this time and try this query in query analyser, then you can understand the issue.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/14/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

there is no default value in the textbox.I dont no how can i explain my issue?

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 11/14/2011 [Member] Starter | Points: 25

Up
0
Down
please let us seet he html code then the issue will clear to me?

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RohiK on: 11/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

you mean to say restrict user if he click on search without inserting value in textbox

if yes then simple solution - just put required filed validator for that textbox.

Happy Programming!!
Rohi

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

presently developing windows applications not an web applications.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RohiK on: 11/15/2011 [Member] Starter | Points: 25

Login to post response