i have code to read empty row in database, if no row in database then textbox = "0"
my code :
protected void CheckNota()
{
string vNota;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd1 = new SqlCommand("select ISNULL ((KdNota), 0) as vKdNota from tProdukBeliHead where KdNota = '" + txtKdBeli.Text.Trim() + "'", con))
//using (SqlCommand cmd1 = new SqlCommand("select KdNota from tProdukBeliHead where KdNota = '" + txtKdBeli.Text.Trim() + "'", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd1))
{
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0]["vKdNota"] == DBNull.Value)
{
vNota = "0";
}
else
{
vNota = dt.Rows[0]["KdNota"].ToString();
}
}
}
}
}
but textbox not showing value 0, only report this : There is no row at position 0.
thank you
dt.Rows[0]won't exist. You should check that the datatable actually has rows. Have a look at this: stackoverflow.com/questions/6264554/…KdNotain your query. KdNota <> vKdNota