1.当然不用写4个,具体就看你怎么做了
2.这是以前一个网友提供的,我还没来得及验证,你可以参考一下:你先在VS。NET中做一个WEB SERVICE,如:CustomerCodeService.asmx
------------------------------------------------------
<%@ WebService Language="vb" Codebehind="CustomerCodeService.asmx.vb" Class="CustomerCodeService" %>
CustomerCodeService.asmx.vb
------------------------------------------------------
Imports System.Web.Services
Imports System.Xml.Serialization
Public Class CustomerCodeInfo
    <XmlElement()> _
            Public CodeIsValid As Boolean
    <XmlElement()> _
            Public ID As String
    <XmlElement()> _
            Public Name As String
    <XmlElement()> _
            Public Currency As String
End Class
<WebService(Namespace:="http://dotAge.com/")> _
Public Class CustomerCodeService
    Inherits System.Web.Services.WebService
#Region " Web Services Designer Generated Code "
    Public Sub New()
        MyBase.New()
        'This call is required by the Web Services Designer.
        InitializeComponent()
        'Add your own initialization code after the InitializeComponent() call
    End Sub
    'Required by the Web Services Designer
    Private components As System.ComponentModel.IContainer
    'NOTE: The following procedure is required by the Web Services Designer
    'It can be modified using the Web Services Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        'CODEGEN: This procedure is required by the Web Services Designer
        'Do not modify it using the code editor.
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
#End Region
    <WebMethod()> Public Function GetCustomerCodeInfo(ByVal CustomerCode As String) As CustomerCodeInfo
        Dim C As New DataAccess.Customer()
        GetCustomerCodeInfo = New CustomerCodeInfo()
        If C.GetInfo(CustomerCode) Then
            GetCustomerCodeInfo.CodeIsValid = True
            GetCustomerCodeInfo.ID = Trim(C.Code)
            GetCustomerCodeInfo.Name = Trim(C.Name)
            GetCustomerCodeInfo.Currency = Trim(C.Currency)
        Else
            GetCustomerCodeInfo.CodeIsValid = False
        End If
        C = Nothing
    End Function
End Class
然后在页面的写如下客户端脚本,就可以不刷新得到客户的几个属性填写以FORM中的控件中
<script language=javascript>
var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
objXMLDoc.async = false;
objXMLDoc.load( "CustomerCodeService.asmx/GetCustomerCodeInfo?CustomerCode=" + escape(f.value));
CodeIsValid = objXMLDoc.selectSingleNode("//CustomerCodeInfo/CodeIsValid") ;
if (CodeIsValid.text=="true") {
frmID.value = objXMLDoc.selectSingleNode("//CustomerCodeInfo/ID").text ;
frmName.value = objXMLDoc.selectSingleNode("//CustomerCodeInfo/Name").text ;
frmCurrency.value = objXMLDoc.selectSingleNode("//CustomerCodeInfo/Currency").text ;
} else {
alert("Customer code is invalid !") ;
}
</script>
以上frmID, frmName, frmCurrency 都是FORM中的INPUT TYPE=TEXT

解决方案 »

  1.   

    1。在WEB.COFIG里加代码
        <appSettings>
            <add key="DBConnectionString1" value="server=localhost;uid=sa;pwd=yourpw;database=db1" />
    <add key="DBConnectionString2" value="server=localhost;uid=sa;pwd=yourpw;database=db2" /><add key="DBConnectionString3" value="server=localhost;uid=sa;pwd=yourpw;database=db3" /><add key="DBConnectionString4" value="server=localhost;uid=sa;pwd=yourpw;database=db4" />    </appSettings>
    在aspx里要使用数据库连接的地方加入
    dim sqlcon as new sqlconnection(DBConnectionString1) 就是连接db1,依此类推
      

  2.   

    在web.config里面添加如下字段
        <appSettings>         <add key="DBConnectionString1" value="server=local;uid=username;pwd=password;database=yourdb1" />
            <add key="DBConnectionString2" value="server=local;uid=username;pwd=password;database=yourdb2" />
            <add key="DBConnectionString3" value="server=local;uid=username;pwd=password;database=yourdb3" />
            <add key="DBConnectionString4" value="server=local;uid=username;pwd=password;database=yourdb4" />
         </appSettings>
    里面一共四个<add          />每一个换成你连接数据库的连接字段在aspx页面里面
    在<script language="vb" runat=server>前面
    page_load前面
    加上Dim DBConnectionString1 As String = ConfigurationSettings.AppSettings("DBConnectionString1")
    Dim DBConnectionString2 As String = ConfigurationSettings.AppSettings("DBConnectionString2")
    Dim DBConnectionString3 As String = ConfigurationSettings.AppSettings("DBConnectionString3")
    Dim DBConnectionString4 As String = ConfigurationSettings.AppSettings("DBConnectionString4")依次为你连接四个数据库的连接字段
    在程序当中每次需要写连接到数据库的字段的时候
    就用DBConnectionString1 2 3 4 代替
    第二个问题我不会
      

  3.   

    2、你可以用一个WebSerice来生成一个XML,在页面(客户端)用Microsoft.XMLDOM读取,基本能“实现”无刷新
      

  4.   

    : gOODiDEA(无语) 
    他的数据库经常刷新,不知道这样行吗?
      

  5.   

    TO; csdnshao(不是程序员)
    我觉得不需要考虑数据库刷新的问题,我只想实现网页上的数据间隔两秒就自动的更新一次.但必须要无刷新,就像我们在网上聊天室聊天一样!
    TO;terryxin(有聊的冬季) 
    框架结构是肯定不行的
    TO;kld3000(汪洋)
    感谢您给我这个提示,但是我问的意思是说如何将4个大体相同的东西,写成个类!
      

  6.   

    同意 yuanylong(小新) 
    SQL SERVER2000 数据视图,只要数据结构不常改动,这是一个好方案
      

  7.   

    第一个用DataSet不行吗?
    第二个不会!
      

  8.   

    1.建立一个WebSerice返回查询的DataSet。。2.获取XML文档。。
    XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    XmlHttp.open("POST", "你的WebService",false);
    XmlHttp.Send()
    xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
    xmlDoc.async = false;
    xmlDoc.load(XmlHttp.responseXML);
    GetValue(xmlDoc);3.查找节点建立表格。。function GetValue(xmlDoc)

    var ID;
    ID = xmlDoc.documentElement.selectNodes("//ID");
    numRow=ID.length;
         。。
             其它各个节点将值付给数组。。
         。。
    initTable(numRow,numCell); 。。行列数生成表格
              
    AddItem();。。添加数据。。}function initTable(nRow,nCell)
    {
      根据行列数生成表格。。
    }function AddItem()
    {
       给表格付值
    }4.根据下面的循环调用就可以了。。
    function LoopExecuteWs()
    {
    XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    XmlHttp.open("POST", "你的WebService",false);
    XmlHttp.Send()
    xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
    xmlDoc.async = false;
    xmlDoc.load(XmlHttp.responseXML)
    GetValue(xmlDoc);
    setTimeout("LoopExecuteWs()",1000);
    }
      

  9.   

    算了,CSDN网友已经的回答.我想就目前为止.我还是没有一个清晰的思路去解决我的这两个问题.我想先解决第一各问题:写数据库表格查询,读取的类!这个类要想完整的写出来,对我这样的新手是不简单了!希望大家继续给我好的建议!在这里我要真心的感谢以下几位网友:gangganghao(ganggang) ;gOODiDEA(无语);yqdeng(享受生活每一天); ajihzs(阿己)
      

  10.   

    对于数据库操作,一般要写一个专门的类,我觉得这样对于数据库的操作是最方便的,而且对于你以后的项目也很有用的,对于多个连接最好在webconfig里配置几个连接参数,然后把返回结果放在一个dataset的多个table 里,如果要保存状态,可以加到viewstate里!