Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net Refreshing SQL Views when new columns are added to a table

Hi

I have a SQL database that has multiple Views. When I add a new column into one of the tables used in these views this doesn't automatically refresh the Views. I have to go and manually recreate them. Having posed the question on whether this can be refreshed automatically I received a "no" as the answer. I  want to write VB.net code to do this. I need help with the best way to go about this.
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

When you add a column or delete a column from the table and if your view uses * in the column list then use below command to update the view. You can easily do this in the SQL itself. Dont write the VB.NEt code. Try below once!!

ALTER TABLE yourtableName	
  ADD column_name INT;

EXECUTE sp_refreshview N'YourViewName'; 

Open in new window

Avatar of Murray Brown

ASKER

Thanks. I have to do this in VB.net because it is for the users of my app. Surely there is a way to do exactly what you are doing via VB.net
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much. I appreciate the help
Avatar of Éric Moreau
buy using select * is not considered a best practice!