0

I have a textbox(Nume) and I do a search in oracle sql database and display it in crystal report. The question is how can I search from another one column and display it. Like name and prename in the same textbox (search multiple strings in multiple columns), in my situation from nume and prenume.

OleDbConnection con = new OleDbConnection("Provider=MSDAORA;Data Source=desktop-2hiivbv;Persist Security Info=True;Password=*****;User ID=STUDENT");
OleDbDataAdapter da;
DataSet ds;
public string strSQl;

protected void Cauta_Click(object sender, EventArgs e)
{
    try
    {
        strSQl = "select * from angajati where nume ='" + this.ToTitleCase(Nume.Text) + "'";
        da = new OleDbDataAdapter(strSQl, con);
        ds = new DataSet();
        da.Fill(ds, "angajati");
    }
    catch (Exception ex)
    {
        //   MessageBox.Show(ex.Message.ToString());
    }
    CrystalReport raport = new CrystalReport();
    raport.SetDataSource(ds.Tables["angajati"]);
    CrystalReportViewer1.ReportSource = raport;
}

the table is this

CREATE TABLE angajati (
                        nr_crt int primary key,
                        nume varchar(20) not null,
                        prenume varchar(20) not null
)
2
  • Just for a clarification, You have a text box and you want to search multiple columns of your table for text box value right? Commented Dec 3, 2016 at 16:51
  • yes @RangaDewasinghe Commented Dec 3, 2016 at 16:53

1 Answer 1

1

Try changing your SQL query as follows.(I assume your other column is "prename")

strSQl = "select * from angajati where nume ='" + this.ToTitleCase(Nume.Text) + "' or prename="+ this.ToTitleCase(Nume.Text) + "';
Sign up to request clarification or add additional context in comments.

3 Comments

it's working partial, but if i write name and prename there is no answer...blank @RangaDewasinghe
@SereDaniel Yeah. This should behave like that. So you want to search multiple strings in multiple columns which are typed on the same textbox then? This will not be possible. The only thing you can do with this limitations, use SQL LIKE condition. But it will not be helpful either.
If we can get multiple search criteria as delimited,Maybe we can write some query for your requirement. @SereDaniel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.