我正在處理一個項目,並且因爲「命令文本未設置爲命令對象」而出現錯誤。 我的代碼是:沒有爲命令對象設置命令文本
query = "select Top 10
Name,
R_Line2,
BirthDate,
BirthTime,
Height,
Weight,
BirthCity,
BirthCountry,
FatherName,
MonthlyIncome,
FamilyIncome,
Add1,
Add2,
PinCode,
Tel1,
Tel2
from InpRegistration
where DateDiff('yyyy', [Birthdate],
Now()) BETWEEN @AgeFrom AND
@AgeTo and Weight BETWEEN @MinWeight AND
@MaxWeight and Height BETWEEN @MinHeight AND @MaxHeight and
MonthlyIncome BETWEEN @MinIncome AND @MaxIncome";
connf.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\project\Milan_Data.mdb";
connf.Open();
OleDbCommand cmdf = new OleDbCommand(query, connf);
cmdf.CommandType = CommandType.Text;
cmdf.Parameters.AddWithValue("@AgeFrom", ddlminage.SelectedItem.Text);
cmdf.Parameters.AddWithValue("@AgeTo", ddlmaxage.SelectedItem.Text);
cmdf.Parameters.AddWithValue("@MinWeight", ddlweightmin.SelectedValue);
cmdf.Parameters.AddWithValue("@MaxWeight", ddlweightmax.SelectedValue);
cmdf.Parameters.AddWithValue("@MinHeight", ddlheightmin.SelectedValue);
cmdf.Parameters.AddWithValue("@MaxHeight", ddlheightmax.SelectedValue);
cmdf.Parameters.AddWithValue("@MinIncome", ddlminincome.SelectedItem.Text);
cmdf.Parameters.AddWithValue("@MinIncome", ddlmaxincome.SelectedItem.Text);
OleDbDataAdapter daf = new OleDbDataAdapter(cmdf);
DataSet dsf = new DataSet();
daf.Fill(dsf);
Repeater2.DataSource = dsf;
Repeater2.DataBind();
connf.Close();
請幫助我。我在網上搜索這個,但沒有得到任何解決方案。 Similar Problem,。在此先感謝...
嘗試聲明一個查詢變量作爲sqlcommand數據類型 –
你聲明你的查詢是什麼? –
我已經聲明查詢爲字符串 –