Searching the data from DB

Posted by Gokul under Regular Expressions on 11/26/2010 | Points: 10 | Views : 1319 | Status : [Member] | Replies : 4
Hi friends,

I have various textboxes as name, password, mobile no, address, e-mail id and gender. I have palced a grid to view these data from DB. i also kept a search button with the above said fields as name, password, moblie no,address and gender. Now according to the details entered in those textboxes the values should be checked from the DB. If there is a match then the matched datas should be displayed in the grid.
Note:
If any atleast one input is given in those textboxes , the search should display the results accordingly in the grid v kept.

Thanks and Regards,
GokulNath Nithy.



Responses

Posted by: Lalji_mer on: 11/26/2010 [Member] Bronze | Points: 25
Posted by: Vuyiswamb on: 11/26/2010 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Look at this
http://www.codeproject.com/KB/cs/N-Tier22.aspx

Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: T.saravanan on: 11/29/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Gokul,

Refer the following code.. You got some idea about data filter...

// Get Condition from TextBox Controls

private string GetCondition()
{
string sCondition=string.Empty;
if(txtName.Text !=string.Empty)
{
sCondition = "Name = 'txtName.Text' ;
}
else if(txtMobile.Text !=string.Empty)
{
if(sCondition !=string.Empty)
{
sCondition += " AND ";
}
sCondition += "[Mobile No]= 'txtMobile.Text' ;
}
.
.
.
.
.
.
else if(txtGender.Text !=string.Empty)
{
if(sCondition !=string.Empty)
{
sCondition += " AND ";
}
sCondition += "[Gender]= 'txtGender.Text' ;
}
return sCondition ;
}

// Get Data
private void GetData()
{
string sCondition=GetCondition();
if(sCondition != string.Empty)
{
// In your query condition
string strSql ="select * from table where "+sCondition +;
// Pass this string into your database and get the data to bind in your grid.
dgvGrid.DataSource =dt.Copy();
dgvGrid.DataBind();
}
else
{
// alert message ("Please Enter a input")
}
}


Try this way...

Cheers :)

Thanks,
T.Saravanan

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

Posted by: Gokul on: 11/29/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Saravanan..... Your code exactly suits my issue.. Thank tou vry much. Continue the gud job. If i ve any more querry ll come out wit that. Thanks once again.

Cheers... Keep rocking as u r....

Thanks and Regards,
GokulNath Nithy.

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

Login to post response