MS Access (SELECT mname, mcellno WHERE mcellno LIKE '0922*') を介してクエリを実行しようとしましたが、その結果、希望のデータが表示されました。これは
private Int32 getMemberNo()
{
con.ConnectionString = db.konek();
String sql = "SELECT COUNT(*) AS x FROM members";
Int32 count = 0;
try
{
con.Open();
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
{
count = Convert.ToInt32(rdr["x"].ToString());
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex);
}
finally
{
con.Close();
}
return count;
}
public String[,] displayMobilePrefix() //THIS FUNCTION
{
con.ConnectionString = db.konek();
String sql = "SELECT mname, mcellno FROM members WHERE mcellno LIKE '" + @mcellno + "*'";
int count = this.getMemberNo();
String[,] ars = new String[2, count];
try
{
con.Open();
OleDbCommand cmd = new OleDbCommand(sql, con);
cmd.Parameters.Add("@mcellno", OleDbType.VarChar, 30).Value = this.mcellno;
OleDbDataReader rdr = cmd.ExecuteReader();
int counter = 0;
while (rdr.Read())
{
ars[0, counter] = rdr["mname"].ToString();
ars[1, counter] = rdr["mcellno"].ToString();
counter++;
}
}
finally
{
con.Close();
}
return ars; //never returns any data
}
データは返されません。ただし、文字列クエリにパラメーターを追加しようとしましたが、何も返されません。