TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Srikanth Suryadevara
NA
37
26.6k
Open Data Reader Associated with the command
Apr 10 2014 3:12 PM
Int64 amnt = Convert.ToInt64(TextBox1.Text);
int dur = Convert.ToInt16(DropDownList1.SelectedItem.Text);
int intr=5;
switch (dur)
{
case 1:
intr = 5;
break;
case 2:
intr = 7;
break;
case 3:
intr = 9;
break;
}
SqlConnection scn = new SqlConnection(@"Data Source=SRIKANTH\MYNEWSQL;Initial Catalog=OnlineBankingServer;Integrated Security=true;");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
try
{
scn.Open();
cmd.Connection = scn;
cmd.CommandText = "select accnt_bal from Cust_Details where account_num=" + uid;
dr = cmd.ExecuteReader();
string invok = "no";
while (dr.Read())
{
if (Convert.ToInt64(dr["accnt_bal"]) > amnt)
invok = "yes";
}
dr.Close();
if (invok == "yes")
{
TransactionNumberGenerator tr = new TransactionNumberGenerator();
Int64 invnum = tr.fxdinvgen();
cmd.CommandText = "select Inv_Id from Fixd_Inv where account_num=" + uid + " and act='yes'";
dr = cmd.ExecuteReader();
while (dr.Read())
{
if (Convert.ToInt64(dr["Inv_Id"]) == invnum)
invnum = tr.fxdinvgen();
}
dr.Close();
cmd.CommandText = "insert into Fixd_Inv values(" + uid + "," + invnum + "," + amnt + "," + intr + "," + dur +",DATEADD(yyyy,"+dur+",CURRENT_TIMESTAMP),'yes')";
cmd.ExecuteReader();
dr.Close();
Int64 tid = tr.transact_gen();
cmd.CommandText = "select tid from Transactions where account_num=" + uid;
dr = cmd.ExecuteReader();
while (dr.Read())
{
if (Convert.ToInt64(dr["tid"]) == tid)
tid = tr.transact_gen();
}
dr.Close();
cmd.CommandText = "insert into Transactions values(" + uid + "," + tid + ",'finv'" + amnt + ",CURRENT_TIMESTAMP)";
cmd.ExecuteNonQuery();
Label1.ForeColor = Color.Green;
Label1.Text = "Amount Invested Successful, Your Investment Number is : " + invnum;
}
else
{
Label1.ForeColor = Color.Red;
Label1.Text = "Insufficient amount in your account";
}
}
catch (Exception ex)
{
Label1.ForeColor = Color.OrangeRed;
Label1.Text = ex.Message;
}
}
}
I wrote this code but i am getting an error
There is a datareader opened associated with this command which must be closed first
Reply
Answers (
1
)
how to generate reset password link for only one time use
how to validate with Sql database?