Click here to Skip to main content
15,916,091 members
Home / Discussions / Database
   

Database

 
GeneralDataTable Constraints not working... Pin
kenhall3-Jun-03 7:23
kenhall3-Jun-03 7:23 
GeneralRe: DataTable Constraints not working... Pin
kenhall4-Jun-03 7:27
kenhall4-Jun-03 7:27 
GeneralTemp table and data adapter problem Pin
Mike Osbahr3-Jun-03 4:26
Mike Osbahr3-Jun-03 4:26 
GeneralSQLBindParameter not used for all parameters Pin
kenhall2-Jun-03 10:19
kenhall2-Jun-03 10:19 
Generalbizaare sql server 7 + ado/asp error Pin
Nathan Ridley2-Jun-03 1:56
Nathan Ridley2-Jun-03 1:56 
GeneralRe: bizaare sql server 7 + ado/asp error Pin
basementman2-Jun-03 9:29
basementman2-Jun-03 9:29 
GeneralRe: bizaare sql server 7 + ado/asp error Pin
Nathan Ridley2-Jun-03 14:14
Nathan Ridley2-Jun-03 14:14 
GeneralDataset Table.Select strExpr problem Pin
kenhall31-May-03 23:56
kenhall31-May-03 23:56 
I am trying to search through a dataset dataTable to find a value based on a search string. I am using the DataTable.Select method but I am having trouble with the search string when it contains the single quote character.
I have tried escaping the single quote with a "\", but I still get errors.

How do you escape special characters in the select string when using the DataTable.Select method?

public string ReturnId(string tableName, string field, string searchValue)
{
// query table return DataRow
// searchValue must be Escaped for SQL special chars.
// this will return -1 for not found
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatatableclassselecttopic2.asp
string idFound = "-1";
DataTable myTable = ds.Tables[ tableName ];
string strExpr;
// strings must be enclosed in single quotes for these expressions
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassexpressiontopic.asp
strExpr = field + " = '" + searchValue +"'";
DataRow[] foundRows;
// Use the Select method to find all rows matching the filter.
// In this app, these best be unique
try
{
foundRows = myTable.Select(strExpr);
if ( foundRows.Length != 0 )
{
switch (tableName)
{
case "asset":
idFound = (foundRows[0]["asset_id"]).ToString(); // row 0, column 0 asset_id
break;
case "keyvalue":
idFound = (foundRows[0]["value_id"]).ToString(); // row 0, column 0 value_id
break;
case "filevalue":
idFound = (foundRows[0]["value_id"]).ToString(); // row 0, column 0 value_id
break;
}

}
}
catch(Exception err)
{
MessageBox.Show(err.ToString() + "\r\n" +strExpr.ToString());
}

return idFound;
}

GeneralRe: Dataset Table.Select strExpr problem Pin
andyharman1-Jun-03 0:58
professionalandyharman1-Jun-03 0:58 
GeneralRe: Dataset Table.Select strExpr problem Pin
kenhall2-Jun-03 10:13
kenhall2-Jun-03 10:13 
GeneralADOX Creating table fileds, which allow Zero length Pin
Mayank Goyal31-May-03 3:37
Mayank Goyal31-May-03 3:37 
GeneralBatch update from XML Pin
Hesham Amin30-May-03 8:25
Hesham Amin30-May-03 8:25 
GeneralRe: Batch update from XML Pin
Paul Watson31-May-03 9:50
sitebuilderPaul Watson31-May-03 9:50 
GeneralRe: Batch update from XML Pin
Hesham Amin31-May-03 11:23
Hesham Amin31-May-03 11:23 
GeneralDB engines for software local/file DB (no server running) Pin
Jean-Marc Molina29-May-03 14:12
Jean-Marc Molina29-May-03 14:12 
GeneralRe: DB engines for software local/file DB (no server running) Pin
andyharman30-May-03 3:19
professionalandyharman30-May-03 3:19 
GeneralRe: DB engines for software local/file DB (no server running) Pin
Jean-Marc Molina31-May-03 9:40
Jean-Marc Molina31-May-03 9:40 
GeneralRe: DB engines for software local/file DB (no server running) Pin
andyharman1-Jun-03 0:49
professionalandyharman1-Jun-03 0:49 
GeneralException Mapping Pin
slah29-May-03 2:36
slah29-May-03 2:36 
QuestionHow to create query on query in MFC Pin
soundman3228-May-03 21:40
soundman3228-May-03 21:40 
AnswerRe: How to create query on query in MFC Pin
basementman29-May-03 6:31
basementman29-May-03 6:31 
GeneralRe: How to create query on query in MFC Pin
soundman322-Jun-03 22:43
soundman322-Jun-03 22:43 
GeneralRe: How to create query on query in .NET Pin
Mike Osbahr3-Jun-03 3:41
Mike Osbahr3-Jun-03 3:41 
GeneralINNER JOIN within DataSet Pin
Dr_Sh0ck28-May-03 18:43
Dr_Sh0ck28-May-03 18:43 
GeneralRe: INNER JOIN within DataSet Pin
andyharman30-May-03 3:24
professionalandyharman30-May-03 3:24 

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.