alter table add column through Dreamweaver ... need to get this to work ASAP! :(

Thread Solved

Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

alter table add column through Dreamweaver ... need to get this to work ASAP! :(

 
0
  #1
Jun 2nd, 2008
Hi,

Im trying to work out a way for users to be able to add new columns to tables in an SQL Server database through Dreamweaver.

I have tried using stored procedures but i keep getting errors. The user will choose which table they wish to add a column then give that column a name and datatype. I just cant get it to work so i tried to go back to basics and not use stored procedures but just code the SQL stating the tablename, columnname and datatype. This seems to work :-

  1. <%
  2. set addcolumn = Server.CreateObject("ADODB.Command")
  3. addcolumn.ActiveConnection = MM_Silverwingdatabase_STRING
  4. addcolumn.CommandText = "ALTER TABLE dbo.customer ADD newcolumn VarChar(50)"
  5. addcolumn.Execute()
  6.  
  7. %>

how can I change this so the user can choose the table and then give the column a name and datatype? or even my next step... how can i change this so the user can just enter the tablename?

any ideas would be great!!!!! Ive been working on this for a long time and need to get it to work ASAP!

Thanks!
GLT
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 98
Reputation: GLT is an unknown quantity at this point 
Solved Threads: 0
GLT GLT is offline Offline
Junior Poster in Training

Re: alter table add column through Dreamweaver ... need to get this to work ASAP! :(

 
1
  #2
Jun 2nd, 2008
Sorted it myself! well... the table bit anyway but i think the rest will be quite straight forward now. I'll post this so anyone else who is having this problem can solve it.

You have to pass the variables from a form on another page like you would creating search page and results page.

code for form:-

  1. <form name="form1" method="post" action="TESTaddcolumn.asp">
  2. <table width="50%" border="1">
  3. <tr>
  4. <td>Table Name </td>
  5. <td><input type="text" name="texttablename"></td>
  6. <td><input type="submit" name="insert" value="insert"></td>
  7. </tr>
  8. </table>
  9. </form>

form action points to the page with the asp command and stored procedure.

code for command:-

  1. <%
  2.  
  3. Dim cmd_addcolumnTEST__tablename
  4. cmd_addcolumnTEST__tablename = "1"
  5. if(Request("texttablename") <> "") then cmd_addcolumnTEST__tablename = Request("texttablename")
  6.  
  7. %>
  8. <%
  9.  
  10. set cmd_addcolumnTEST = Server.CreateObject("ADODB.Command")
  11. cmd_addcolumnTEST.ActiveConnection = MM_Silverwingdatabase_STRING
  12. cmd_addcolumnTEST.CommandText = "dbo.sp_addcolumnTEST"
  13. cmd_addcolumnTEST.CommandType = 4
  14. cmd_addcolumnTEST.CommandTimeout = 0
  15. cmd_addcolumnTEST.Prepared = true
  16. cmd_addcolumnTEST.Parameters.Append cmd_addcolumnTEST.CreateParameter("@RETURN_VALUE", 3, 4)
  17. cmd_addcolumnTEST.Parameters.Append cmd_addcolumnTEST.CreateParameter("@tablename", 200, 1,50,cmd_addcolumnTEST__tablename)
  18. cmd_addcolumnTEST.Execute()

There may be other ways of doing this but after much frustration i found this way worked.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC