wpf - How to count number of rows in a sql table with vb.net using sqlclient class -


select count(*) table name  

this above code work fine in standalone sql table, can simple task in vb.net wpf project ?

this sample ..just check , try own way.

sample:

dim connetionstring string dim connection sqlconnection dim command sqlcommand dim sql string connetionstring = "data source=servername;initial catalog=databasename;                    user id=username;password=password"  sql = "select count(*) table"  connection = new sqlconnection(connetionstring)  try    connection.open()    command = new sqlcommand(sql, connection)    dim sqlreader sqldatareader = command.executereader()    while sqlreader.read()    msgbox("count =" & sqlreader.item(0))    end while    sqlreader.close()    command.dispose()    connection.close()   catch ex exception   msgbox("can not open connection ! ")  end try 

if query return more 1 values can use sqldatareader(), if sure query return single value can use executescalar() , if query wont return result, eg:- insert.it insert value not return data can use executenonquery().the executenonquery() return result indicate successful or failure. if want can assign same else no need.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -