ASP 显示数据库内容

ASP 显示数据库内容,第1张

<%

'建立数据连接

Dim ConnStr, Conn

ConnStr = "Provider=MicrosoftJetOLEDB40;Data Source=" & ServerMapPath("/usermdb")

Set Conn = ServerCreateObject("ADODBConnection")

ConnOpen ConnStr

'数据库数据查询

Dim sql, rs

sql = "Select From info"

Set rs = ServerCreateObject("AdodbRecordset")

rsOpen sql, Conn, 1, 1

'下面是数据输出

ResponseWrite("<table width='100%' border='0' cellpadding='0' cellspacing='0'>") & vbCrLf

ResponseWrite(" <tr>") & vbCrLf

ResponseWrite(" <td height='30'>id</td>") & vbCrLf

ResponseWrite(" <td>username</td>") & vbCrLf

ResponseWrite(" <td>password</td>") & vbCrLf

ResponseWrite(" <td>sex</td>") & vbCrLf

ResponseWrite(" <td>personalinfo</td>") & vbCrLf

ResponseWrite(" <td>ntime</td>") & vbCrLf

ResponseWrite(" </tr>") & vbCrLf

If rsBOF And rsEOF Then

ResponseWrite("查无数据!")

Else

Do While Not rsEOF

ResponseWrite(" <tr>") & vbCrLf

ResponseWrite(" <td height='30'>" & rs("id") & "</td>") & vbCrLf

ResponseWrite(" <td>" & rs("username") & "</td>") & vbCrLf

ResponseWrite(" <td>" & rs("password") & "</td>") & vbCrLf

ResponseWrite(" <td>" & rs("sex") & "</td>") & vbCrLf

ResponseWrite(" <td>" & rs("personalinfo") & "</td>") & vbCrLf

ResponseWrite(" <td>" & rs("ntime") & "</td>") & vbCrLf

ResponseWrite(" </tr>") & vbCrLf

rsMoveNext

Loop

End If

ResponseWrite("</table>") & vbCrLf

'关闭数据库

rsClose

Set rs = Nothing

ConnClose

Set Conn = Nothing

%>

这是全部代码,认真仔细的研究每一句代码,能全部理解的话 那asp基本就等于入门了 加油!:)

你这种方式数据入库的话,1000w条数据,要连接1000w次数据库的,性能肯定是差的,因为建立一次数据库连接是开销很大的 *** 作

数据库的插入是支持多条的啊

insert into 表(字段) values (值),(值2),(值3)

这样就可以连接一次数据库,插入多条数据了,可以把1000w条数据分几组,这样连接数据库的次数会大大减少,性能自然就好了

若想利用此方法达到反向同步则可能出现问题,比如想在parkfee数据库有新数据插入时让当前数据库也同时插入一条记录,建立一个触发器,则形成了一个循环触发,当插入数据时会报大于最大递归次数错。因此因避免这样的触发循环,若要达到类似效果还须想别的方法。(待续)

补充:

若两个库处于不同的数据库服务器则应先进行以下 *** 作:

在 server1 上创建连接服务器,以便在 server1 中 *** 作 server2,实现同步

exec sp_addlinkedserver 'server2','','SQLOLEDB','server2的数据库实例名或ip'

exec sp_addlinkedsrvlogin 'server2','false',null,'用户名','密码'

go

已经测试,创建并运行下面的存储过程可以循环添加数据:

create procedure dowhile()

begin

declare i int default 0;

start transaction;

while i<50 do

insert into users(userId,userName,userPwd) values(null,concat('s00',i),123456);

set i=i+1;

end while;

commit;

end;

delimiter;

for (int i = 0; i < dtRowsCount; i++)

{

string strex = "insert into pub_ExcellenceProject(id,projectCode,mainid,bank,Fujia,newTechnologyProject,GreenBuild,Others,insertUserName,insertTime,updateUserName,updateTime)";

strex += " VALUES ( " + SysConvertToDBString(dtRows[i]["id"]ToString());

strex += " , " + SysConvertToDBString(dtRows[i]["projectCode"]ToString());

strex += " ," + SysConvertToDBString(dtRows[i]["mainid"]ToString());

strex += " , " + SysConvertToInt32(dtRows[i]["bank"]ToString());

strex += " ," + SysConvertToDBString(dtRows[i]["Fujia"]ToString());

strex += " ," + SysConvertToDBString(dtRows[i]["newTechnologyProject"]ToString());

strex += " , " + SysConvertToDBString(dtRows[i]["GreenBuild"]ToString());

strex += " ," + SysConvertToDBString(dtRows[i]["Others"]ToString());

strex += " , " + SysConvertToDBString(dtRows[i]["insertUserName"]ToString());

strex += " ," + SysConvertToDBString(SysConvertToDateTimeString(DateTimeParse(dtRows[i]["insertTime"]ToString())));

strex += " , " + SysConvertToDBString(dtRows[i]["updateUserName"]ToString());

strex += " ," + SysConvertToDBString(SysConvertToDateTimeString(DateTimeParse( dtRows[i]["updateTime"]ToString())));

strex += " )";

sqlcmdCommandText = strex;

sqlcmdExecuteNonQuery();

}

就可以了

dt是一个数据源

filePath文件路径

filePostfix 文件后缀

public bool InsertAppurtenance(string filePath, string fileName, string filePostfix,string remark,int isshare)

{

bool flag = false;

SqlCommand comm = (SqlCommand)SysUtilGetCommand();

//判断文件名称的长度

if (fileNameLength > 300)

{

fileName = fileNameSubstring(0, 300);

}

try

{

//内容

FileStream fs = new FileStream(filePath, FileModeOpen, FileAccessRead);

byte[] fileContent = new byte[fsLength];

fsRead(fileContent, 0, (int)fsLength);

fsClose();

//文件大小

decimal size = ConvertToDecimal(FileSize(filePath));

//组合sql语句

string strSql = stringEmpty;

strSql = "INSERT INTO jzs_FileInfoDir(ID,fatherProjectCode,fileName,ParentID,fileContent,filePostfix,IsDirectory,IsShare,userId,remark,insertTime,insertUserName,updateTime,updateUserName) VALUES(";

strSql += "'" + GuidNewGuid()ToString();///

strSql += "','" + ProjectInfoFatherProjectCode + "',";

strSql += "'" + fileName + "',";

strSql += "'" + pid + "',";

strSql += "@FileContent,";

strSql += "'" + filePostfix + "',";

strSql += "0 ";

strSql += " ," + SysConvertToInt32(isshare);

strSql += "," + SysConvertToDBString(manager);

strSql += " ,"+SysConvertToDBString(remark);

strSql += ", " + SysConvertToDBString(SysConvertToDateTimeString(SystemInfoCurrentDate))+ ",";

strSql += "'" + LoginUserInfoId + "'";

strSql += "," +SysConvertToDBString(SysConvertToDateTimeString(SystemInfoCurrentDate))+ ",";

strSql += "'" + LoginUserInfoId + "'";

strSql += ")";

commCommandText = strSql;

SqlParameter para = new SqlParameter("@FileContent", SqlDbTypeImage);

paraValue = fileContent;

commParametersAdd(para);

commExecuteNonQuery();

flag= true;

}

catch (Exception)

{

MessageBoxShow(fileName + "" + filePostfix + "已经被打开,请关闭后重新添加。", "系统提示", MessageBoxButtonsOK, MessageBoxIconWarning);

flag= false;

}

finally

{

commConnectionClose();

}

return flag;

}

以上就是关于ASP 显示数据库内容全部的内容,包括:ASP 显示数据库内容、php foreach循环输入insert数据库、在mysql中的两个不同的数据库之间建立触发器连接等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9387745.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存