Checking for data
-
Hi Guys and Gals, I have my c# win form app connected up to a sql compact db. I have a form which contains fields to enter company data, ie an address. Now at the moment when I open that form, I do a read to see if a record exists... xDataSourceAccess = AppSet.DataSourceAccess; conn = new SqlCeConnection(Properties.Settings.Default.CS_Account + xDataSourceAccess); string strRecordExisit = "SELECT OID from tbl_CompanyDetails"; conn.Open(); cmd = new SqlCeCommand(strRecordExisit,conn); Reader = cmd.ExecuteReader(); if (Reader.Read()) xRecordFound = true; Reader.Close(); etc.... Is this the the best way to check to see if a record exists? (ie best performance and memory usage) thanks
-
Hi Guys and Gals, I have my c# win form app connected up to a sql compact db. I have a form which contains fields to enter company data, ie an address. Now at the moment when I open that form, I do a read to see if a record exists... xDataSourceAccess = AppSet.DataSourceAccess; conn = new SqlCeConnection(Properties.Settings.Default.CS_Account + xDataSourceAccess); string strRecordExisit = "SELECT OID from tbl_CompanyDetails"; conn.Open(); cmd = new SqlCeCommand(strRecordExisit,conn); Reader = cmd.ExecuteReader(); if (Reader.Read()) xRecordFound = true; Reader.Close(); etc.... Is this the the best way to check to see if a record exists? (ie best performance and memory usage) thanks
Yep, pretty much. Any other methods you use are going to boil down to the same technique. Though, I'd probably have a stored procedure that checks for the existance and passes back a True/False, or a record count if there is more than one record your checking for in the same table.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Yep, pretty much. Any other methods you use are going to boil down to the same technique. Though, I'd probably have a stored procedure that checks for the existance and passes back a True/False, or a record count if there is more than one record your checking for in the same table.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008IIRC you can't use stored procedures in SQL Compact.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) -
IIRC you can't use stored procedures in SQL Compact.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)Hmmm...didn't know that. I've never used it before, having gone only as low as Express. Just goes to show you what "assume" really stands for! :-D
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008