Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C# Programming

C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-25-2008, 09:05 AM
Siten0308 Siten0308 is offline
Learning Programmer
 
Join Date: Jun 2008
Posts: 58
Rep Power: 1
Siten0308 is on a distinguished road
Default wild card string search in C#

Hello

Sorry to bug but more info the better my knowledge will grow right? well anyways on with the question: what is the code to search a wild card in a SQL database after successfully attaching it to your C# program? this wild card for example user can enter telephone number, first name, last name etc and it will pull up the entire user information or if there are a couple of users with the same name, there will be a list below the search bar and you can choose the correct one? i have an idea however it is in SQL running a query like select column from table where = ? or whatever, but how does that go in C# if a person types in a text box for the wild card search and clicks the button?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-25-2008, 09:52 AM
gaylo565's Avatar   
gaylo565 gaylo565 is offline
Programmer
 
Join Date: May 2007
Location: flagstaff, az
Posts: 147
Last Blog:
String Manipulation wi...
Rep Power: 6
gaylo565 has a spectacular aura aboutgaylo565 has a spectacular aura about
Default Re: wild card string search in C#

Here is a simple example of an sql query executed in c# on the Northwind database that is included with sql express server. It gets all the specified rows from the Orders table who's Customer Id contains intCustomerID (The variable isn't defined in the scope of this code but can be retrieved from a text box or set some other way. It is called a parameter and is only there to narrow down our search.)
Code:
try
{
    Set up the data connection    
    DataConnection.ConnectionString = 
        "Integrated Security = true;"+
        "Initial Catalog = Northwind;"+
        "Data Scource = ServerName\\SQLEXPRESS";
    dataConnection.Open()
    SqlCommand dataCommand = new SqlCommand();
    dataCommand.Connection = dataConnection;
    //set up actual sql query
    dataCommand.CommandText =
        "SELECT OrderID, OrderDate, "+
        "ShipName";
    //You can do this all in one command but 
    //I split it up to make it easier to read    
    dataCommand.CommandText +=
        "FROM Orders WHERE CustomerID '"+intCustomerID+"'";
    //call dataReader class to execute dataCommand
    SqlDataReader = dataCommand.ExecuteReader();
    //create loop to iterate through the records;
    while (dataReader.Read())
    {
        //Do something with your returned records
        intorderId = dataReader.GetInt32(0):
        if(dataReader.IsDBNull(2)
        {
             MessageBox.Show("Order {0} not yet shipped)
        }
        else
        {
            DateTime orderDate = dataReader.GetDateTime(1);
            string shipName = dataReader.GetString(3);
        }
    }
    dataReader.Close();
}
catch(Exception e)
{
    MessageBox.Show(e.Message, "Error accessing the database:", MessageBoxButtons.OK);
}
finally
{
    dataConnection.Close()
}
Keep in mind this is a very simple example. You should also look into creating a data set for your information. The method I used above locks th rows being queried while in use and is therefor considered inefficient for multiuser db applications. A data set is more complicated but worth learning for the sort of application you want to build.
This is a decent intro to data sets: Using the DataSet - Using ADO.NET with SQL Server - Developer Fusion - Visual Basic, C# Programming, ASP.NET, .NET Framework and Java Tutorials

Last edited by gaylo565; 06-25-2008 at 10:52 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-25-2008, 03:21 PM
Siten0308 Siten0308 is offline
Learning Programmer
 
Join Date: Jun 2008
Posts: 58
Rep Power: 1
Siten0308 is on a distinguished road
Default Re: wild card string search in C#

Alright this is some bull %^$@^!, i know i saw this dang post in C# tutorial, please gaylo565 say you this post in also C# tutorial? i just logged in and find this post here, whats the deal?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-26-2008, 09:04 AM
gaylo565's Avatar   
gaylo565 gaylo565 is offline
Programmer
 
Join Date: May 2007
Location: flagstaff, az
Posts: 147
Last Blog:
String Manipulation wi...
Rep Power: 6
gaylo565 has a spectacular aura aboutgaylo565 has a spectacular aura about
Default Re: wild card string search in C#

???Your confusing me??? This post isn't a repeat. I put a bit of time into typing this up from a sample project I did a while back, and simplifying it to make a good example. I just looked through the c# tutorials and didn't see anything like this. Where do you say you saw this post before???....Sorry I just caught up on my post reading and now I get what it is your talking about. It wasn't in the tutorials section when I commented on it. It could have been at one point but an admin moved it if that was the case.

Last edited by gaylo565; 06-26-2008 at 09:19 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-26-2008, 09:36 AM
Siten0308 Siten0308 is offline
Learning Programmer
 
Join Date: Jun 2008
Posts: 58
Rep Power: 1
Siten0308 is on a distinguished road
Default Re: wild card string search in C#

Sorry gaylo565, thanks for your assistance with your example posted, it was great information especially very handy to anyone who would be using it in a professional environment. on the other topic of my posts being moved, nevermind, i am confused my self, i am just going to read posts for now on instead of asking so i dont get kicked off this forum website
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 06-26-2008, 09:43 AM
gaylo565's Avatar   
gaylo565 gaylo565 is offline
Programmer
 
Join Date: May 2007
Location: flagstaff, az
Posts: 147
Last Blog:
String Manipulation wi...
Rep Power: 6
gaylo565 has a spectacular aura aboutgaylo565 has a spectacular aura about
Default Re: wild card string search in C#

No worries Hopefully they don't get that carried away and all your posts get to the right spot.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Hacking John Tutorials 6 07-22-2008 09:37 AM
wild card string search in C# Siten0308 C# Programming 4 06-24-2008 10:35 PM
wild card string search in C# Siten0308 C# Programming 3 06-24-2008 01:12 PM
Problem removing from ArrayList (affects Vector as well) chunkit Java Help 0 03-30-2008 10:36 PM


All times are GMT -5. The time now is 11:13 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
sam ........ 20.00000
gaylo565 ........ 18.00000
|pH| ........ 15.00000
WingedPanther ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads