Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / March 2004

Tip: Looking for answers? Try searching our database.

Error in the Function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sats - 23 Mar 2004 18:52 GMT
I am trying to write a function to check whether the selected value
(thru SQL query)is avalable in table or not,but every time in the
below function, CheckValue is becoming true.Can any one help me where
am I going wrong.

Private Function CheckValue() As Boolean
       
       Dim cn As SqlCeConnection
       Dim cmd As SqlCeCommand
       Dim dr As SqlCeDataReader
       Const strLocalConnect As String = "Data
Source=\Windows\sql.sdf"
       cn = New SqlCeConnection(strLocalConnect)
       cn.Open()
       Dim CheckSql As String
      CheckSql = "Select Assetid  FROM Asset WHERE Assetid ='" &
VarValue & "'"
       'MsgBox(CheckSql)
       cmd = New SqlCeCommand(CheckSql, cn)
       dr = cmd.ExecuteReader()
       dr.Read()
       
       If dr.IsClosed = False Then
           CheckValue= True
       Else
           CheckValue= False
       End If

       cn.Close()
       dr = Nothing

   End Function
Paul G. Tobey [eMVP] - 23 Mar 2004 19:04 GMT
Wouldn't it make more sense to check for a non-zero number of result rows?
Maybe something like this:

-----
SqlCommand cmd = new SqlCommand( theQueryText, sqlconnect );

DataSet ds = new DataSet();

SqlDataAdapter adapter = new SqlDataAdapter();

adapter.SelectCommand = cmd;

adapter.Fill(ds);

DataTable    dt = ds.Tables[ 0 ];

bool    res;

if ( dt.Rows > 0 )

   res = true;

else

   res = false;

return res;

-----

Paul T.

> I am trying to write a function to check whether the selected value
> (thru SQL query)is avalable in table or not,but every time in the
[quoted text clipped - 28 lines]
>
>     End Function

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.