ASP gets the database table name, field name, and some operations on the field
Recently, in the ASP forum to see a lot of netizens asked how to get the database table name, field name and how to delete the field, add the operation so write this article.
I am more familiar with SQL Server, so SQL Server is the column:
<%
SET conn=server.createobject ("ADODB. Connection ")
Conn.Open "SERVER=IP address; provider=sqloledb;database= library name; uid= user name; pwd= password; "
%>
Read the table name in the SQL Server library:
<%
Set Rs=conn.openschema (20)
While not Rs. Eof
Response.Write ("Database name:" & RS (0) & "<br>")
Response.Write ("Owner:" & RS (1) & "<br>")
Response.Write ("Table name:" & RS (2) & "<br>")
Response.Write ("Table Type:" & RS (3) & "<br>")
Rs. MoveNext
Wend
%>
So, we know the name of the table, and now we'll look at how to manipulate the table's fields.
Suppose: There are tables in the database: [Things], table fields: Id,thingsname,thingstype
Get all field names for this table:
<%
Dim I,j,sql
Set rs=server.createobject ("ADODB. Recordset ")
Sql= "SELECT * from [things] where 1<>1"
Rs.Open sql,conn,1,1
J=rs. Fields.Count
For I=0 to (J-1)
Response.Write ("& i+1 &" field Name: "& Rs.) Fields (i). Name & "<br><br>")
Next
%>
OK, now we understand how to get the field name.
This is also possible if you want to do something about the field values that you get:
For example, if we want to delete the field thingstype in the table [things], we can
To write like this:
<%
Sql= "ALTER TABLE [things] DROP COLUMN thingstype"
Conn.execute SQL
%>
Another example is we want to add a field thingscolor, which is type varchar, length 20, and the default value is red, as follows:
<%
Sql= "ALTER TABLE [things] ADD thingscolor VARCHAR () DEFAULT ' Red '"
Conn.execute SQL
%>
The above basic operation of the field is implemented in SQL language, in ASP, through the SQL language, we can only have sufficient permissions to complete
More database operations, such as using Create to build tables, delete tables with drop, etc.
Finally, I caishuxueqian, this article certainly will have the mistake place, also hoped that everybody criticizes.
Also hope that everyone in the CSDN text message to me to discuss together, thank you!