Your query:
Select MAX(IS NULL(no),0)+1) from billdetail1
gives a result:
Next in the code, you are trying to read results from column named:
no
TextBox1.Text = dr("no").ToString()
Take a look at result (above table) and tell me where is a field named
no
?
So... replace your query with:
Select ISNULL(MAX([no]),0)+1 AS [no] FROM billdetail1
Read more about:
IDENTITY[
^]
[EDIT name="second look"]
I see one potential risk in the way you are trying to get the number of billdetail. Let say 2 users in the same time open a form. Your query will return for them billdetail [no] = 5. What's happen when they will try to save data? You'll get duplicates.
That's why the most important is to set identity (increment) - go to above link, example A - for the column named [no]
Of course, before save data, you can re-query a [no] to get max+1, but it not guarantee non-duplicates numbers.[/EDIT]