| | |
Simply Search Engine
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2009
Posts: 12
Reputation:
Solved Threads: 0
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.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
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.
•
•
Join Date: Jun 2009
Posts: 88
Reputation:
Solved Threads: 12
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:
or
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!
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:
C# Syntax (Toggle Plain Text)
"SELECT * FROM BOOK_DB WHERE BookName =" + nameOfNameTextBox.Text.ToString()
C# Syntax (Toggle Plain Text)
"SELECT * FROM BOOK_DB WHERE BookDate =" + nameOfDateTextBox.Text.ToString()
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!
•
•
Join Date: Jun 2009
Posts: 12
Reputation:
Solved Threads: 0
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();
}
}
}
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();
}
}
}
•
•
Join Date: Jun 2009
Posts: 88
Reputation:
Solved Threads: 12
You are more or less the right way.
A problem i can see in your code is in the line:
It needs to be only ", and not '";
And after you have done:
You need to read the data so use 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?
A problem i can see in your code is in the line:
•
•
•
•
SqlCommand cmd = new SqlCommand("SELECT * from book WHERE dateofpurchase = '" + txtDate.Text.ToString());
And after you have done:
•
•
•
•
SqlDataReader dr;
dr = cmd.ExecuteReader();
C# Syntax (Toggle Plain Text)
dr.Read();
Now what more help do you need, have you tried to run this code?,
is it working?, do you get what you want?
Wrap up source code with BB code tags.
Read this sample:
Read this sample:
C# Syntax (Toggle Plain Text)
DateTime dt; // if date is invalid DateTime.MinValue will be assigned to dt DateTime.TryParse(textBox1.Text, out dt); string q = ""; if (dt == DateTime.MinValue) { q = "select * from table1 where name like '" + textBox1.Text + "%'"; } else { q = "select * from table1 where mydate='" + textBox1.Text + "'"; }
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- Search Engine Optimization Manager for SalesOnlineWorld (Internet Marketing Job Offers)
- Search Engine Optimization Manager (Internet Marketing Job Offers)
- experienced Search Engine Optimizer's and Soft works (Post your Resume)
- UK Search Engine Marketing Services (Post your Resume)
- Search Engine Manager needed (Internet Marketing Job Offers)
- Search Engine Optimization (SEO) / Link Building / PPC Management / SEM Services (Post your Resume)
- Make google your default search engine (Windows tips 'n' tweaks)
- Increase Search Engine Position (Ad Space for Sale)
- a few search engine optimization questions (Search Engine Optimization)
Other Threads in the C# Forum
- Previous Thread: Need some beginnerhelp
- Next Thread: nifty little counter problem (timer involved)
| Thread Tools | Search this Thread |
.net access ado.net algorithm api array barchart bitmap box broadcast buttons c# check checkbox client combobox control conversion csharp custom database datagrid datagridview dataset datetime decryption degrees development drag draganddrop drawing encryption enum event excel file form format forms function gdi+ grantorrevokepermissionthroughc#.net httpwebrequest image index input install java label list listbox mandelbrot marshalbyrefobject math mouseclick mysql netcfsvcutil.exe numeric operator path photoshop php picturebox pixelinversion platform polynomial post programming properties radians regex remote remoting richtextbox server sleep socket sql statistics stream string study table teamsuite text textbox thread time timer update usb usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml






