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
Inderjeet Kaur
NA
24
3.1k
Display value from database in textbox using c# oop
Apr 9 2021 5:48 AM
class Balance : DbConnection
{
public string bal { set; get; }
public bool Load_Balance()
{
connectDb.Open();
SqlDataReader rd;
bool check = false;
using (var cmd = new SqlCommand())
{
cmd.CommandText = "SELECT * Student WHERE Balance=@bal";
cmd.CommandType = CommandType.Text;
cmd.Connection = connectDb;
cmd.Parameters.Add("@bal", SqlDbType.VarChar).Value = bal;
rd = cmd.ExecuteReader();
while (rd.Read())
{
check = true;
}
connectDb.Close();
}
return check;
}
rd shows error bcz it doesn't exist here.
How can I fix it?
I have a connection class(DbConnection) and wanted to display value from database in another form.
public void verify_bal()
{
Balance Bal = new Balance();
bool verify = Bal.Load_Balance();
if (verify == true)
{
txtBucks.Text = rd.GetValue(5).ToString;
}
else
{
MessageBox.Show("No!!");
}
}
Reply
Answers (
1
)
How to improve the functionality of this code in the face of new requi
change my test exam project to make any exam into 3 categories