Following how to select specific feid using a filter from access in C#
I have another question:
I recall this method whit a click event of SelectFeedbtn_Click
and it works:
public static void GetSelectedFeed(Form2 frm2)
{
string StrCon = System.Configuration.ConfigurationManager.ConnectionStrings["FeedLibraryConnectionString"].ConnectionString;
OleDbConnection Connection = new OleDbConnection(StrCon);
OleDbDataAdapter DataA = new OleDbDataAdapter("Select * from FeedLibrary", Connection);
DataTable DTable = new DataTable();
DataA.Fill(DTable);
frm2.SelectedFeeddataGridView.DataSource = DTable;
}
but when I want to get an ID from FeedSelectListBox
that DisplayMember
is Feed Name / Description and ValueMember
is ID it shows an exeption: {"Data type mismatch in criteria expression."}
,
the query is:
public static void GetSelectedFeed(Form2 frm2)
{
string StrCon = System.Configuration.ConfigurationManager.ConnectionStrings["FeedLibraryConnectionString"].ConnectionString;
OleDbConnection Connection = new OleDbConnection(StrCon);
OleDbDataAdapter DataA = new OleDbDataAdapter("Select * from FeedLibrary where ID = 'frm2.FeedSelectListBox.SelectedValue'", Connection);
DataTable DTable = new DataTable();
DataA.Fill(DTable);
frm2.SelectedFeeddataGridView.DataSource = DTable;
}
What should I do ?
First thing, ID is an int so it should not be passed in quotes ''
. You are passing frm2.FeedSelectListBox.SelectedValue
as a string in query but you should pass its value with in the query so that it gets evaluated and your query becomes executable.
OleDbDataAdapter DataA = new OleDbDataAdapter("Select * from FeedLibrary where ID = "+frm2.FeedSelectListBox.SelectedValue, Connection);
OleDbDataAdapter DataA = new OleDbDataAdapter("Select * from FeedLibrary where ID = "+FeedSelectedID, Connection);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.