|
||
|
|
#1 (permalink) |
|
Forum Expert
|
Im using the visual C# studio express and im trying to make an phone number rgram that will hold multiple name phone number town etc entry, i did all the tutorial about how to connect the SQL to my application how to create one etc, ut the only part they didnt say is how to search an item in the database.
Here is a quick explanation of my forms 2 radiobutton one is opname and one is oplastname textbox ( for entering the search request. one quit button one edit button ( to add and remove entry for database ) one search button actually i want to be able to search either in the name or lastname columns in the database Name and the other Lastname depending on wich radiobutton they choose so far my code look like that. public void bcsearch_OnClick() { string searchtype = ""; if ( opname.Checked == true ) searchtype = "Name"; else if ( oplastname.Checked == true ) searchtype = "Lastname": } and... thats about it.... i think you figure out why i made these if statement it will be to use the variable searchtype instead of the name of the column. can somone help me please?
__________________
Admin of Crystal World, French shard Under Construction http://www.crystalworld.over-blog.com/ If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation. Last edited by jocan2003; 04-18-2007 at 10:29 PM. Reason: switched way to work from SQL database to XML files |
|
|
|
|
|
#2 (permalink) |
|
Forum Expert
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
|
Ok, Im confused about what your question is exactly? You dont know how to run and handle queries to a database in C#?
__________________
Useful links (Use them or die in a fire!!!): Ultimate Little Guide, C# Tutorials & Docs, RunUO Basic Scripts, Run UO How to..., Configure server for connections, Scripting for Dummies, Common Problem Solutions, FAQ Forum, RunUO Wiki, Basic Generics, Xml Tutorial |
|
|
|
|
|
#3 (permalink) |
|
Forum Expert
|
i know how to get them show on my forms one by one or in table, and also how to modify them, but i dont know how to actualy search for a specific entry
__________________
Admin of Crystal World, French shard Under Construction http://www.crystalworld.over-blog.com/ If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation. |
|
|
|
|
|
#4 (permalink) |
|
Forum Expert
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
|
you mean like this?
Code:
SELECT * FROM Database WHERE column = value
__________________
Useful links (Use them or die in a fire!!!): Ultimate Little Guide, C# Tutorials & Docs, RunUO Basic Scripts, Run UO How to..., Configure server for connections, Scripting for Dummies, Common Problem Solutions, FAQ Forum, RunUO Wiki, Basic Generics, Xml Tutorial |
|
|
|
|
|
#5 (permalink) |
|
Forum Expert
|
i dont think i can write that in the bcsearch_OnClick event can i ? using sql code in that CSharp OnClick event wont be a problem?
__________________
Admin of Crystal World, French shard Under Construction http://www.crystalworld.over-blog.com/ If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation. |
|
|
|
|
|
#6 (permalink) |
|
Forum Expert
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
|
Youll have to set it up as the query, send it to the database, and just handle the result.
__________________
Useful links (Use them or die in a fire!!!): Ultimate Little Guide, C# Tutorials & Docs, RunUO Basic Scripts, Run UO How to..., Configure server for connections, Scripting for Dummies, Common Problem Solutions, FAQ Forum, RunUO Wiki, Basic Generics, Xml Tutorial |
|
|
|
|
|
#7 (permalink) |
|
Forum Expert
|
well the only things i know is from this tutorial
Beginner Developer Learning Center: Absolute Beginner's Series 8 i dont know much else about making query as he only show basic stuff, from the OOP wich mean didnt show anything relate to SQL coding.... ***edit*** if you dont mind, can you help me going step by step into that? i dont even know where to start.... I thik i found soimething out, im using visual C# studio studio 2005 wich is free from microsoft, right now im binding a listbox to the database, but while doing that i saw a little add query so i tought i could write the *search* in that, but look like i cant, here is what i see. ![]() can you guide me from here?
__________________
Admin of Crystal World, French shard Under Construction http://www.crystalworld.over-blog.com/ If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation. Last edited by jocan2003; 04-18-2007 at 03:58 PM. |
|
|
|
|
|
#8 (permalink) |
|
Forum Expert
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
|
Hmmm, see if this will help you out
![]() Beginners guide to accessing SQL Server through C# - The Code Project - C# Database
__________________
Useful links (Use them or die in a fire!!!): Ultimate Little Guide, C# Tutorials & Docs, RunUO Basic Scripts, Run UO How to..., Configure server for connections, Scripting for Dummies, Common Problem Solutions, FAQ Forum, RunUO Wiki, Basic Generics, Xml Tutorial |
|
|
|
|
|
#9 (permalink) |
|
Forum Expert
|
Well after some tries i gave upop, i will look at it later, instead im using XML file to store my data, and its now working so far, but only one problem, here is my code for the event.
Code:
private void button3_Click(object sender, EventArgs e)
{
Form2 fm = new Form2();
XmlDocument docXML = new XmlDocument();
docXML.Load("Liste.xml");
string strsearchentry = this.textBox1.Text.ToString();
XmlElement nodRoot = docXML.DocumentElement;
XmlNodeList nodItems = nodRoot.GetElementsByTagName("nom");
int p = nodItems.Count;
string[] itemsarray = new string[p];
for (int i = 0; i < nodItems.Count; i++)
{
//fm.listBox1.Items.Add(nodItems[i].InnerXml);
itemsarray[i] = nodItems[i].InnerText.ToString();
}
foreach (string item in itemsarray)
{
if (strsearchentry == item)
fm.listBox1.Items.Add(item);
}
/*for (int i = 0; i < fm.listBox1.Items.Count; i++)
{
string stradd = fm.listBox1.FindString(strsearchentry);
}*/
fm.Show();
}
I.E.; i search only for joc, but it doesnt return the jocan item, how can i make it so it will return jocan even if the strsearchentry only contain joc?
__________________
Admin of Crystal World, French shard Under Construction http://www.crystalworld.over-blog.com/ If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation. |
|
|
|
|
|
#10 (permalink) |
|
Forum Expert
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
|
You can use String.Contains();
Like so: Code:
string search = "Joc";
string[] data = new string[] { "Jocan", "Jock", "Bob", "George" };
foreach (string s in data)
{
if (s.Contains(search))
//its there
else
//its not
}
__________________
Useful links (Use them or die in a fire!!!): Ultimate Little Guide, C# Tutorials & Docs, RunUO Basic Scripts, Run UO How to..., Configure server for connections, Scripting for Dummies, Common Problem Solutions, FAQ Forum, RunUO Wiki, Basic Generics, Xml Tutorial |
|
|
|
|
|
#11 (permalink) |
|
Forum Expert
|
thanks you very very much
![]()
__________________
Admin of Crystal World, French shard Under Construction http://www.crystalworld.over-blog.com/ If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation. |
|
|
|
|
|
#12 (permalink) |
|
Forum Expert
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
|
yep no problem, and keep looking into the SQL though, its really not that hard (although ive only worked with SQLite and c# before) and its definately a better answer to what you are doing.
__________________
Useful links (Use them or die in a fire!!!): Ultimate Little Guide, C# Tutorials & Docs, RunUO Basic Scripts, Run UO How to..., Configure server for connections, Scripting for Dummies, Common Problem Solutions, FAQ Forum, RunUO Wiki, Basic Generics, Xml Tutorial |
|
|
|
|
|
#13 (permalink) |
|
Forum Expert
|
im only writing up a small phone book as a personal project trying to learn everything in same time, so i will go where it look like a bit easier the time i get better, then i will go on SQL.
also i will be making some game using forms later on, and save game will be save in encoded xml format ( to avoid editing hehe ). but i aso know that iw ill need SQL database to store multple variable that i may use in these game so let start somewhere i wont get lost first at hehe. ++karma fried ![]()
__________________
Admin of Crystal World, French shard Under Construction http://www.crystalworld.over-blog.com/ If there is another lifeform in the universe, they are wise enough to avoid our babaric civilisation. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|