Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 04-18-2007, 04:40 AM   #1 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default Find partial matchs in string.

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
jocan2003 is offline   Reply With Quote
Old 04-18-2007, 03:24 PM   #2 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

Ok, Im confused about what your question is exactly? You dont know how to run and handle queries to a database in C#?
mordero is offline   Reply With Quote
Old 04-18-2007, 03:26 PM   #3 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default

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.
jocan2003 is offline   Reply With Quote
Old 04-18-2007, 03:28 PM   #4 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

you mean like this?

Code:
SELECT * FROM Database WHERE column = value
mordero is offline   Reply With Quote
Old 04-18-2007, 03:30 PM   #5 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default

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.
jocan2003 is offline   Reply With Quote
Old 04-18-2007, 03:36 PM   #6 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

Youll have to set it up as the query, send it to the database, and just handle the result.
mordero is offline   Reply With Quote
Old 04-18-2007, 03:39 PM   #7 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default

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.
jocan2003 is offline   Reply With Quote
Old 04-18-2007, 05:06 PM   #8 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

Hmmm, see if this will help you out
Beginners guide to accessing SQL Server through C# - The Code Project - C# Database
mordero is offline   Reply With Quote
Old 04-18-2007, 10:28 PM   #9 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default

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();
        }
in this one i search and return any item that match the strsearchentry ( wich is what the ppl enter in the search text box ) but how can i verify each item that they include the search entry in their name but not totally.

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.
jocan2003 is offline   Reply With Quote
Old 04-18-2007, 10:41 PM   #10 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

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
}
mordero is offline   Reply With Quote
Old 04-18-2007, 10:42 PM   #11 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default

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.
jocan2003 is offline   Reply With Quote
Old 04-18-2007, 10:54 PM   #12 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

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.
mordero is offline   Reply With Quote
Old 04-18-2007, 10:57 PM   #13 (permalink)
Forum Expert
 
Join Date: Feb 2004
Age: 23
Posts: 488
Send a message via MSN to jocan2003
Default

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.
jocan2003 is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5