-1

I cannot get my search button to take me to the gridview I created on another web form. Below is the Code I am using, I have tried the try/catch code and that gave me errors.

Here the code I have, the only issues with it is when I type in the last name, and hit search, the page does nothing. It will not go to the next page and display on gridview.

OleDbConnection con = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=PayrollSystem_DB.mdb");
con.Open();
string strqrySearch = "SELECT * FROM tblPersonnel where LastName = @LastName";
OleDbCommand com = new OleDbCommand(strqrySearch, con);
com.Parameters.AddWithValue("strqrySearch", txtSearchName.Text.Trim());
OleDbDataReader dr = com.ExecuteReader();

string strFname = "";
string strPayrate = "";
string strStartdate = "";
string strEnddate = "";
while (dr.Read())
{
    strFname = dr["FirstName"].ToString();
    strPayrate = dr["PayRate"].ToString();
    strStartdate = dr["StartDate"].ToString();
    strEnddate = dr["EndDate"].ToString();
    Response.Redirect("frmViewPersonnel.aspx");
}

dr.Close();
con.Close();
4

1 回答 1

0

代替

com.Parameters.AddWithValue("strqrySearch", txtSearchName.Text.Trim());

通过这条线。

com.Parameters.AddWithValue("@LastName", txtSearchName.Text.Trim());
于 2013-06-18T19:57:47.210 回答