Home > Net >  C # how to transfer the ACCESS OleDbParameter parameters LIKE statements?
C # how to transfer the ACCESS OleDbParameter parameters LIKE statements?

Time:10-07

 

Public IEnumerable{
ListEnclosing DataGridViewRowsIndex=0;
String STRSQL=@ "SELECT Shortcuts_ID, Code, Explain, the Content, Images, Shortcuts_MenuTitleForeignKey, Shortcuts_CategoryForeignKey FROM Shortcuts
WHERE the Explain the LIKE? OR the Content LIKE?" ;

OleDbParameter [] parms={new OleDbParameter ("?" , OleDbType. LongVarWChar), new OleDbParameter ("?" , OleDbType. LongVarWChar)};
Parms [0]. Valuehttps://bbs.csdn.net/topics/="' *" + pWhereExplainORContent + "*".
Parms [1]. Valuehttps://bbs.csdn.net/topics/="' *" + pWhereExplainORContent + "*".


The DataTable dt=db. ExecuteDataTable (STRSQL, parms);
{foreach (DataRow row in dt. Rows) list. Add (ToModel (row)); }
return list;
}


I want to pass the statement is:
SELECT Shortcuts_ID, Code, and Explain the Content, Images, Shortcuts_MenuTitleForeignKey, Shortcuts_CategoryForeignKey FROM Shortcuts WHERE the Explain LIKE '* more * OR Content LIKE' * more * '

* * * * * * * * * * * * * * * * * * * *

CodePudding user response:

 
Public DataTable ExecuteDataTable (string cmdText, params OleDbParameter [] ¶s)
{
Using (OleDbConnection con=new OleDbConnection (strcon))
{
con.Open();
Using (OleDbCommand CMD=con. CreateCommand ())
{
Cmd.Com mandText=cmdText;
If (¶s!=null)
{
CMD. The Parameters. AddRange (¶s);
}

The DataTable dt=new DataTable ();
OleDbDataAdapter adapter=new OleDbDataAdapter (CMD);
Adapter. MissingSchemaAction=MissingSchemaAction. AddWithKey;
Adapter. The Fill (dt);
CMD. The Parameters. The Clear ();
Return dt.
}
}
}
//it is strange that I'm no good with pure string concatenation!!!!!!!!!!!!!!!!!!!

String STRSQL=@ "SELECT Shortcuts_ID, Code, Explain, the Content, Images, Shortcuts_MenuTitleForeignKey, Shortcuts_CategoryForeignKey FROM Shortcuts WHERE the Explain LIKE" * "+ pWhereExplainORContent +" * OR Content LIKE "*" + pWhereExplainORContent + "*".



The DataTable dt=db. ExecuteDataTable (STRSQL, null);
{foreach (DataRow row in dt. Rows) list. Add (ToModel (row)); }

return list;

CodePudding user response:

Prompt what mistake posted

CodePudding user response:

OleDbParameter [] parms={new OleDbParameter ("?" , OleDbType. LongVarWChar), new OleDbParameter ("?" , OleDbType. LongVarWChar)};
Parms [0]. Valuehttps://bbs.csdn.net/topics/="' *" + pWhereExplainORContent + "*".
Parms [1]. Valuehttps://bbs.csdn.net/topics/="' *" + pWhereExplainORContent + "*".

Why are you so write

If you are sure you are * the beginning and end are but parameter name you write to

For example,

SELECT * FROM the WHERE NAME=? NAEM AND PASSWORD=? "

Are you? Lack of name

CodePudding user response:

I want to use LIKE statements in ACCESS query can but c # returned empty!!!!!!!!!!

CodePudding user response:

During write c # program USES access database, have a variety of questions baffled, the use of "like" fuzzy query, for example, to use "*" in the access query views do fuzzy matching (SQL is a "%").

Thought the query string in the program should also use the "*", in fact is not the case!

Debugging with "*" in the access database, want to change it with "%" in the program, it is less than any data query, and v is not any wrong, debugging can't find the reason,

To: https://www.cnblogs.com/bile/archive/2013/09/25/3338748.html

CodePudding user response:

Is not addressed to you
  •  Tags:  
  • C#
  • Related