Overclock.net banner

1 - 2 of 2 Posts

·
Registered
Joined
·
5 Posts
Discussion Starter #1
I made a code button to retrieve and display a BOOK record based on the ID typed into the textbox. I suppose to assign all BOOK object properties to the textboxes. But unfortunately, when i click the Find button nothing happens.

Here is my code from my Form1:

protected void btnFind_Click(object sender, EventArgs e)
{
try
{
int iBookID = Convert.ToInt32(this.txtSearch.Text);

string sCnxn = ConfigurationManager.AppSettings["Cnxn"];
string sLogPath = ConfigurationManager.AppSettings["LogPath"];

Books oBookSearch = new Books(sCnxn, iBookID, sLogPath);

if (oBookSearch.ContainsKey(iBookID))
{
this.txtBookTitle.Text = oBookSearch[iBookID].BookTitle.ToString();
this.txtAuthorName.Text = oBookSearch[iBookID].AuthorName.ToString();
this.txtLenght.Text = oBookSearch[iBookID].Lenght.ToString();
this.txtDateCreated.Text = oBooks[iBookID].DateCreated.ToString();

if (oBooks[iBookID].IsOnAmazon.ToString().ToUpper() == "TRUE")
this.chkIsOnAmazon.Checked = true;
else
this.chkIsOnAmazon.Checked = false;
}

this.txtSearch.Text = "";
}
catch (Exception ex)
{
this.lblError.Text = ex.Message;
}
}

And this is my code to the BOOK i BUILD:

public Books(string sCnxn, int iBookID, string sLogPath)
{
try
{
SqlConnection oCnxn = new SqlConnection(sCnxn);

SqlCommand oCmd = new SqlCommand();
oCmd.Connection = oCnxn;

oCmd.CommandType = CommandType.StoredProcedure;
oCmd.CommandText = "spBookSearchID";

oCmd.Parameters.AddWithValue("@BookID", iBookID);

oCnxn.Open();
SqlDataReader oReader = oCmd.ExecuteReader();

while (oReader.Read())
{
Book oBookSearch = new Book();

oBookSearch.BookTitle = oReader["BookTitle"].ToString();
oBookSearch.AuthorName = oReader["AuthorName"].ToString();
oBookSearch.Lenght = Convert.ToInt32(oReader["Lenght"]);
oBookSearch.IsOnAmazon = Convert.ToBoolean(oReader["IsOnAmazon"]);
oBookSearch.BookID = Convert.ToInt32(oReader["BookID"]);
oBookSearch.DateCreated = oReader["DateCreated"].ToString();

if (!this.ContainsKey(oBookSearch.BookID))
this.Add(oBookSearch.BookID, oBookSearch);
}
oCnxn.Close();

}
catch (Exception ex)
{
Log oLog = new Log();
oLog.LogError("BookSearchConstructor", ex.Message, sLogPath);
}
}

Any help would be really appreciated :)
 

·
Registered
Joined
·
2,312 Posts
Use code blocks. I helped you out last week asking 2x that you do that. As a person learning computer science you understand how to use some WYSIWYG tools.
 
1 - 2 of 2 Posts
Top