Simply Search Engine

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2009
Posts: 12
Reputation: dummy C# is an unknown quantity at this point 
Solved Threads: 0
dummy C# dummy C# is offline Offline
Newbie Poster

Simply Search Engine

 
0
  #1
Jun 28th, 2009
i am newbie in C#. i would like to make a button to function as search button to search by name and search by date. When i key in data inside textbox1 for search by name ,then press search ,can get the data from database. Same case to textbox2 for search by date, then press search. Besides, i can use both textbox to search my database at the same time. Example ,i key in name n date together to find a book that i bought ,then press search button. Please help me. i am no idea how to start.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Simply Search Engine

 
0
  #2
Jun 28th, 2009
>Besides, i can use both textbox to search my database at the same time.

if you can search your database, what is the question?
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 12
Reputation: dummy C# is an unknown quantity at this point 
Solved Threads: 0
dummy C# dummy C# is offline Offline
Newbie Poster

Re: Simply Search Engine

 
0
  #3
Jun 29th, 2009
Originally Posted by serkan sendur View Post
>Besides, i can use both textbox to search my database at the same time.

if you can search your database, what is the question?
sorry. i mean i want to search from my database. i not yet start with the code
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Simply Search Engine

 
0
  #4
Jun 29th, 2009
asking this kind of questions is not good. you are not stuck with a problem. you need to grab an ado.net book and read first. or basically go to windowsclient.net and watch video tutorials to learn about datadriven applications. i dont want to write code sample for this because there are milions of them out there. the concepts you are looking for are these : System.Data, System.Data.SqlClient name spaces. then you need SqlConnection and or SqlDataAdapter objects. SqlCommand object maybe. then you need to write your Select statement using SqlParameter object(it will prevent sql injection attacks).
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 12
Reputation: dummy C# is an unknown quantity at this point 
Solved Threads: 0
dummy C# dummy C# is offline Offline
Newbie Poster

Re: Simply Search Engine

 
0
  #5
Jun 29th, 2009
ok. thx alot.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 88
Reputation: IdanS is an unknown quantity at this point 
Solved Threads: 12
IdanS IdanS is offline Offline
Junior Poster in Training

Re: Simply Search Engine

 
0
  #6
Jun 29th, 2009
Hi,

What you need to do is to build your database, after its ready start working on your program.

When you start working on your program, put on your form two textbox and two buttons (when you have different search engine its better to work with different controls for each engine).

Give the textboxs and the buttons names that defined them,
after that press double click on the first button, it will create for you the event method to be fired when the user will press the button, when you have this event method write the code inside.
The code needs to be somthing like that if you using SQL server database:
  1. "SELECT * FROM BOOK_DB WHERE BookName =" + nameOfNameTextBox.Text.ToString()
or
  1. "SELECT * FROM BOOK_DB WHERE BookDate =" + nameOfDateTextBox.Text.ToString()
If not and you dont know how to build your select function for yours database so ask us.

I assum that you know where the querys need to go but if you dont so ask and we will help you.

Of course its just en example and you need to change the query to your needs, but as i said above if you need any help on that two, so ask and we will help you!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 12
Reputation: dummy C# is an unknown quantity at this point 
Solved Threads: 0
dummy C# dummy C# is offline Offline
Newbie Poster

Re: Simply Search Engine

 
0
  #7
Jun 29th, 2009
tq for ur reply. i dont really know how the search engine concept work. pls help me recorrect my code below. thank you in advance.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace WindowsFormsApplication7
{
public partial class Form7 : Form
{
public Form7()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = ConfigurationManager.ConnectionStrings["myConn"].ToString();

myConn.Open();

if (txtTitle.Text != "")
{
SqlCommand cmd = new SqlCommand("SELECT * from book WHERE title = '" + txtTitle.Text.ToString());

SqlDataReader dr;
dr = cmd.ExecuteReader();

dr.Close();
}
else if (txtDate.Text != "")
{
SqlCommand cmd = new SqlCommand("SELECT * from book WHERE dateofpurchase = '" + txtDate.Text.ToString());

SqlDataReader dr;
dr = cmd.ExecuteReader();

dr.Close();
}


myConn.Close();




}
}
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 88
Reputation: IdanS is an unknown quantity at this point 
Solved Threads: 12
IdanS IdanS is offline Offline
Junior Poster in Training

Re: Simply Search Engine

 
0
  #8
Jun 29th, 2009
You are more or less the right way.
A problem i can see in your code is in the line:
SqlCommand cmd = new SqlCommand("SELECT * from book WHERE dateofpurchase = '" + txtDate.Text.ToString());
It needs to be only ", and not '";

And after you have done:
SqlDataReader dr;
dr = cmd.ExecuteReader();
You need to read the data so use
  1. dr.Read();
To read what you set above

Now what more help do you need, have you tried to run this code?,
is it working?, do you get what you want?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,616
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 469
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Simply Search Engine

 
0
  #9
Jun 29th, 2009
Wrap up source code with BB code tags.

Read this sample:
  1. DateTime dt;
  2. // if date is invalid DateTime.MinValue will be assigned to dt
  3. DateTime.TryParse(textBox1.Text, out dt);
  4. string q = "";
  5. if (dt == DateTime.MinValue)
  6. {
  7. q = "select * from table1 where name like '" + textBox1.Text + "%'";
  8. }
  9. else
  10. {
  11. q = "select * from table1 where mydate='" + textBox1.Text + "'";
  12. }
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Simply Search Engine

 
1
  #10
Jun 29th, 2009
the examples above are vulnerable to sql injection. user can enter ' into textbox and can drop the database.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC