|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
i need help for drop colum from table i wrote the below code but it give ERROR:timeout expire
i have one combobox and one button while selecting combox the selected column will drop by clicking the button i have more than 29 columns in the table vmbs and all columns have an entry in the combobox it is working with small tables but it will not work with large tables what can i do plz reply soon sub command1_click() dim db as new adodb.connection dim rs as new adodb.recordset str=com1.text db.open "dsn=jay" set rs=db.excute("select * from vmbs;") sql="alter table vmbs drop column [" & str & " ];" db.excute sql db.close end sub |
|
#2
|
|||
|
|||
|
Why are you opening a recordset first?
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#3
|
||||
|
||||
|
If I understand your problem correctly, you want to select all of the column names from your vmbs table into a combo box. Then you want to have the user press a button after selecting a column to remove it from that table. The first problem is your select statement. You cannot select column names by saying (SELECT * FROM vmbs) because only the records IN the table will appear. If there are no records, this could be what is causing your timeout.
Therefore, you should create a table called say... "vmbscols". Have an ID column (integer & Primary Key with an identity seed) and a colname column (say varchar(30)). Insert all the CURRENT column names from your vmbs table into this new table. Then on your button_click() event set the record source of your combo box to vmbscols table instead of vmbs. Make sure that the bound column of your combo box (com1) is set to the "colname" column of your new table. Once you have done that, then you need to execute two SQL commands. The first will delete a ROW from your vmbscols table, the second will alter the vmbs table to remove the column. For example, first you could set your SQL string to "DELETE FROM vmbscols WHERE colname = " & "'" & com1 & "'" &"". Then db.execute SQL. You could create a second variable, say SQL2 as a string to contain the second SQL statement as in: Dim SQL2 as String SQL2 = "ALTER TABLE vmbs DROP COLUMN " & "'" & com1 & "'" &"" db.execute SQL2 Make sure to put all of this in your button click event. Obviously you will have to adapt this a bit to meet your specific needs. If you are using VBA in Access 2000, you should note that you also have to send keys to refresh the tables, otherwise the combo box will not APPEAR to update (even though it does delete the column, it may remain visible in the combo box). I am putting an example of this below (you will want to put this at the END of your button_click() event). I learned this the hard way, as in Access 2000 the "application.RefreshDatabaseWindow" does not work. SendKeys is not the ideal option, but it works. ' This code is necessary to refresh the table. DoCmd.SelectObject acTable, , True SendKeys "{F5}", True DoCmd.SelectObject acForm, "Form1", False Note that this refreshes the table, then returns you to the form (insert your form name where I put "Form1"). I hope this is helpful for you, please let me know! Also, it would be helpful to know what version of VB you are using so I can better assist you. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > drop column in table dsn |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
![]() |
|