Would be inefficient use of a database!
however you can do this.
you can do a statement:
SELECT COUNT(columnName) FROM tableName
This will count number of entries/records in that table.
Then simply read the value returned using a DataReader
OR
you can fill a datatable/dataset with the records and count the rows to see if there are 15 records, however this would be very inefficient.
So sticking with the first solution...
Dim theSqlCommand as new SqlCommand("SELECT COUNT(columnName) FROM tableName") theSqlCommand.Connection = new SqlConnection(connString) Dim theNumberOfEntries as new object theNumberOfEntries = 0 theSqlCommand.Connection.Open() SqlDataReader theDataReader = theSqlCommand.ExecuteReader(CommandBehaviour.CloseConnection) if theDataReader.HasRows Then theNumberOfEntries = theDataReader.GetValue(0) End If theSqlCommand.Connection.Close() 'We have retrieved and stored the value of the query into theNumberOfEntries if Convert.ToInt32(theNumberOfEntries) = 15 Then 'No more records allowed to be inserted End if |
Does this help?
anyway/anywhere you like
function/sub - totally depends how you are calling it etc.. but generally yes in a sub