By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

Add or Delete a Column in backend database in VB project

Mohan Krishna
100+
P: 115
Hi everyone,
I am doing a project in VB with Access or SQL as backend.
Please help me whether we can Add or Delete a Column in backend database in VB project dynamically (i.e. while running the project) by the client?
Also give me the possible code for both MS Access and SQL to do so.
Thank you all in advance!
Jan 9 '08 #1
Share this Question
Share on Google+
1 Reply


jamesd0142
100+
P: 469
Hi, to add modify this code to suit...

Expand|Select|Wrap|Line Numbers
  1. Try
  2.             Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Users\Users.mdb"
  3.             Dim oConn As New System.Data.OleDb.OleDbConnection(StrConn)
  4.             Dim con As New System.Data.OleDb.OleDbCommand
  5.             con.Connection = oConn
  6.             con.CommandType = CommandType.Text
  7.             con.CommandText = "insert into tblusers (FirstName,LastName,Login,[Password], Passwordchanged) values (" & "'" & txtFirstName.Text & "'," & "'" & txtLastName.Text & "'," & "'" & txtLogin.Text & "'," & "'" & txtPassword.Text & "'," & "'" & strdate & "')"
  8.  
  9.             oConn.Open()
  10.             con.ExecuteNonQuery()
  11.             oConn.Close()
  12.         Catch
  13.         End Try
  14.  
U can also edit the commandtext to delete etc...

Delete row SLQ:
Expand|Select|Wrap|Line Numbers
  1. Delete * from TABLENAME where COLUMNNAME = 'something'
  2.  
Delete columnSLQ:
Expand|Select|Wrap|Line Numbers
  1. alter table TABLENAME 
  2. drop column columnname
  3.  
add column:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tablename
  2.  ADD columnname varchar(50) null
  3.  
Jan 9 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.