Anyone tell me why after pressing the CheckOut button it dont go to the CheckIn button after, this is my code, any questions let me know
string myConnectionString = (string) ConfigurationSettings.AppSettings["ConnectionString"];
// create connection
SqlConnection cnn = new SqlConnection(myConnectionString);
// create command
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
string CheckedOut = "0";
if (CheckedOut == "1")
{
cmd.CommandText = "select * from CheckedOut where CheckedOut = '1'";
CheckOut.Visible = false;
CheckIn.Visible = true;
Console.WriteLine("Please check IN your IR");
}
else
{
cmd.CommandText = "select * from CheckedOut where CheckedOut = '0'";
CheckIn.Visible = false;
CheckOut.Visible = true;
Console.WriteLine("Check OUT IR first");
}
}
Loading

Jan MontanoRank #1,295 · 1.3K reputationPosted Sep 17, 2007, 5:49 PM EDT
How is the Checkout button click event implemented? You have a string CheckedOut initialized to "0". But after the declaration, you use it in a loop condition? I think it will always enter the else condition. Unless you move the "0" initialization somewhere else. and declare string CheckedOut on class level.
Amy Turnbull21 reputationPosted Sep 17, 2007, 11:52 PM EDT
Can you give me an example of a loop condition?
Thanks
Jan MontanoRank #1,295 · 1.3K reputationPosted Sep 18, 2007, 1:10 AM EDT
I was just pointing out that whatever you do, it will not go inside the if (CheckedOut == "1") condition. It won't go inside that condition because of your code string CheckedOut = "0"; right just before it. CheckedOut will always be zero when entering your if condition. You should declare it instead as a class-level variable, and not inside a method.
public Class Test
{
}
Amy Turnbull21 reputationPosted Sep 18, 2007, 1:19 AM EDT
Amy Turnbull21 reputationPosted Sep 18, 2007, 5:08 AM EDT
// create connection
SqlConnection cnn = new SqlConnection(myConnectionString);
// create command
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "BugTrackerWhereCheckedOut";
// add parameters
cmd.Parameters.Add(new SqlParameter("@bg_id", SqlDbType.Int,4));
cmd.Parameters["@bg_id"].Value = Request.QueryString["id"];
cmd.Parameters.Add(new SqlParameter("@us_id", SqlDbType.Int,4));
cmd.Parameters["@us_id"].Value = Convert.ToString(security.this_usid);
// execute and close
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
}
So I have run the store porcedure for this code but how can I get the first column value which is Checkedout that shows if its 0 or 1, is it executereader ?
Amy Turnbull21 reputationPosted Sep 18, 2007, 6:23 AM EDT
santhosh5 reputationPosted Sep 18, 2007, 7:42 AM EDT
ExecuteScalar always return an Object ..how get true or false?
Jan MontanoRank #1,295 · 1.3K reputationPosted Sep 18, 2007, 5:41 PM EDT
How did you use ExecuteScalar?
Did you use it like the code below?
//cmd.CommandText = "SELECT COUNT(*) FROM dbo.region";
Int32 count = (Int32) cmd.ExecuteScalar();
In this example, cmd.ExecuteScalar() is cast as Int32 because we're expecting an int value. In your case, I assume you are expecting a return value of 1 or 0 for your field. It's of numeric data type, you could cast it to int or to to the specific numeric data type so that you'll be able to retrieve it's content correctly.
Regards,
Jan
Amy Turnbull21 reputationPosted Sep 18, 2007, 11:15 PM EDT
string myConnectionString = (string) ConfigurationSettings.AppSettings["ConnectionString"];
// create connection
SqlConnection cnn = new SqlConnection(myConnectionString);
// create command
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "BugTrackerWhereCheckedOut";
// add parameters
cmd.Parameters.Add(new SqlParameter("@bg_id", SqlDbType.Int,4));
cmd.Parameters["@bg_id"].Value = Request.QueryString["id"];
cmd.Parameters.Add(new SqlParameter("@us_id", SqlDbType.Int,4));
cmd.Parameters["@us_id"].Value = Convert.ToString(security.this_usid);
cnn.Open();
if (cmd.ExecuteScalar() != null)
{
Response.Write("record");
string strCheckOutorIn = cmd.ExecuteScalar().ToString();
if (strCheckOutorIn == "true")
{
CheckOut.Visible = false;
CheckIn.Visible = true;
Console.WriteLine("Please check IN your IR");
}
else
{
CheckIn.Visible = false;
CheckOut.Visible = true;
Console.WriteLine("Please Check OUT your IR first");
}
// execute and close
}
else
{
Response.Write("No Record");
}
cnn.Close();
}
and the store procedure is the following
ALTER PROCEDURE [dbo].[BugTrackerWhereCheckedOut]
(
@bg_id int,
@us_id int
) AS
select CheckedOut, bg.bg_id as Bug_ID, us_username as Username
from CheckedOut ck inner join bugs bg on bg.bg_id = ck.bg_id
inner join users us on us.us_id = ck.us_id where ck.bg_id = @bg_id and ck.us_id = @us_id