Another database question

Is it possible and how would I go about making a database full after say 15 Items are added to it that the database would no longer except new entry's
[151 byte] By [Warren13] at [2007-12-23]
# 1

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?

ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2
Ohh that looks like it might do the trick gonna give it a shot
Warren13 at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

Do I write this as a private sub?

Warren13 at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4

anyway/anywhere you like

function/sub - totally depends how you are calling it etc.. but generally yes in a sub

ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...