Click here to Skip to main content
15,892,737 members
Home / Discussions / Database
   

Database

 
AnswerRe: Error with INSERT INTO Pin
enjoycrack8-Sep-05 21:14
enjoycrack8-Sep-05 21:14 
AnswerRe: Error with INSERT INTO Pin
Frank Kerrigan9-Sep-05 0:43
Frank Kerrigan9-Sep-05 0:43 
GeneralRe: Error with INSERT INTO Pin
miah alom9-Sep-05 5:41
miah alom9-Sep-05 5:41 
QuestionRe: Error with INSERT INTO Pin
°[Halo]°11-Sep-05 22:43
°[Halo]°11-Sep-05 22:43 
AnswerRe: Error with INSERT INTO Pin
QuietKnight13-Sep-05 11:16
QuietKnight13-Sep-05 11:16 
GeneralRe: Error with INSERT INTO Pin
QuietKnight13-Sep-05 11:18
QuietKnight13-Sep-05 11:18 
Questionabout SQL ... Pin
mostafa_h8-Sep-05 9:25
mostafa_h8-Sep-05 9:25 
AnswerRe: about SQL ... Pin
Colin Angus Mackay8-Sep-05 10:57
Colin Angus Mackay8-Sep-05 10:57 
So, you want a query that will search by telephone. If telephone is null you want to seach by name and family instead.

This is the query you want:
SELECT * 
FROM MyTable
WHERE (telephone=@telephone AND @telephone IS NOT NULL)
OR ((family = @family AND name = @name) AND @telephone IS NULL)


And the C# code to go with it:
string mySearch = "SELECT * "+
"FROM MyTable "+
"WHERE (telephone=@telephone AND @telephone IS NOT NULL) "+
"OR ((family = @family AND name = @name) AND @telephone IS NULL)";
SqlCommand cmd = SqlCommand(mySearch, myConnection);
cmd.Parameters.Add("@telephone", telephoneNumber);
cmd.Parameters.Add("@name", name);
cmd.Parameters.Add("@family", family);
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
    // Do what you need to do with each row from the table.
}


From the code above telephoneNumber needs to be an object as it needs to be able to supply a System.DBNull.Value in place of the number. You could set this up like this:
object telephoneNumber;
if (telephoneNumberTextBox.Text == "")
    telephoneNumber = System.DBNull.Value;
else
    telephoneNumber = telephoneNumberTextBox.Text;


By the way, I'm not sure storing a telephone number as a decimal is the best approach. Certainly I've always stored them as strings and I've never seen them stored in any numeric format. How do you deal with phone number that start with a zero, or international numbers that are stored with a country independent prefix of +, or special service phone numbers that include the * or #.

Does this help?


My: Blog | Photos

"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious


GeneralRe: about SQL ... Pin
mostafa_h8-Sep-05 15:24
mostafa_h8-Sep-05 15:24 
GeneralRe: about SQL ... Pin
Colin Angus Mackay8-Sep-05 20:08
Colin Angus Mackay8-Sep-05 20:08 
GeneralRe: about SQL ... Pin
mostafa_h14-Sep-05 20:17
mostafa_h14-Sep-05 20:17 
GeneralRe: about SQL ... Pin
Colin Angus Mackay14-Sep-05 20:29
Colin Angus Mackay14-Sep-05 20:29 
GeneralRe: about SQL ... Pin
mostafa_h14-Sep-05 21:19
mostafa_h14-Sep-05 21:19 
GeneralRe: about SQL ... Pin
Colin Angus Mackay15-Sep-05 2:47
Colin Angus Mackay15-Sep-05 2:47 
GeneralRe: about SQL ... Pin
mostafa_h15-Sep-05 3:32
mostafa_h15-Sep-05 3:32 
QuestionDataGrid new row Pin
airbus3808-Sep-05 6:01
airbus3808-Sep-05 6:01 
AnswerRe: DataGrid new row Pin
enjoycrack8-Sep-05 23:51
enjoycrack8-Sep-05 23:51 
AnswerRe: DataGrid new row Pin
miah alom9-Sep-05 5:54
miah alom9-Sep-05 5:54 
QuestionMS Hierarchical FlexGrid Pin
pjhenry12168-Sep-05 5:32
pjhenry12168-Sep-05 5:32 
AnswerRe: MS Hierarchical FlexGrid Pin
smita_roy8-Sep-05 19:59
smita_roy8-Sep-05 19:59 
QuestionT-Sql problem Pin
WDI8-Sep-05 4:55
WDI8-Sep-05 4:55 
AnswerRe: T-Sql problem Pin
Colin Angus Mackay8-Sep-05 10:39
Colin Angus Mackay8-Sep-05 10:39 
GeneralRe: T-Sql problem Pin
Frank Kerrigan9-Sep-05 0:37
Frank Kerrigan9-Sep-05 0:37 
QuestionCall a variable from the another Form ... Pin
mostafa_h7-Sep-05 21:38
mostafa_h7-Sep-05 21:38 
AnswerRe: Call a variable from the another Form ... Pin
enjoycrack8-Sep-05 0:44
enjoycrack8-Sep-05 0:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.