|
||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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? |
| Sponsored Links |
|
|
|
|||||
|
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()
}
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. |
|
|||
|
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?
|
|
|||
|
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
|
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| 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 |
Goal: 100,000 Posts
Complete: 67%