Hi Guys,, I'm try to sum number from database using DataReader and then the value will showing to textbox. If from database the value row is zero will retrun value 1 in textbox, If from database the value row is 1 will retrun value 2 and so on in textbox by automatic read exist value from database. How to solve this problem. Anny help could be appriciate.
this is is the code bihind
private void CariCicilanKe()
{
using (SqlConnection con = new SqlConnection(koneksi))
{
using (SqlCommand cmd = new SqlCommand())
{
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select Count(*) from tbl_pembayaran where id_pinjaman = '" + txtid_pinjaman.Text.Trim() + "'";
using (SqlDataReader rdr = cmd.ExecuteReader())
{
rdr.Read();
if(rdr.HasRows)
{
//If from database the value row is zero will retrun value 1 in textbox
txtcicilan_ke.Text = Convert.ToString(1);
}
else
{
//If from database the value row is 1will retrun value 2 and so on in textbox by automatic read exist value from database
//How to solve this problem, this code not working.
txtcicilan_ke.Text = rdr["cicilan_ke"].ToString() + 1;
}
}
cmd.Connection.Close();
con.Close();
}
}
}
Tri SetiaPosted Jun 13, 2021, 5:48 AM
Tri SetiaPosted Jun 7, 2021, 11:34 AM
Sachin SinghPosted Jun 7, 2021, 9:13 AM
Tri SetiaPosted Jun 7, 2021, 6:11 AM
@Nitin Sontakke
I has been try the code sir, but directly retruning value 2 in textbox when code running.
when I'm entry data 0 on field cicilan_ke it should show value is 1 on textbox and then save the data to database. after that code read again the value on field cicilan_ke and will show 2 on textbox.
Tri SetiaPosted Jun 7, 2021, 5:40 AM
@Jignesh Kumar
exactly is return value of rows sir,, I want the textbox fill automatic number, with this condition If from database the value row is zero will retrun value 1 in textbox and If from database the value row is 1 will return value 2 and so on in textbox by automatic read exist value from database.
Nitin SontakkePosted Jun 7, 2021, 4:25 AM
Jignesh KumarPosted Jun 7, 2021, 4:14 AM