. NET MVC displays data from different databases (MSSQL, MySQL) with the same page

Source: Internet
Author: User
Tags mssql

Controller:
Private ReadOnlyVipviewmodel _model =NewVipviewmodel (); Public Static stringMSG;//Get:systemmanage/renzheng[HttpGet] PublicActionResult Index (intpage =1) { #regionData is populated to the custom modelvardb =Congfig.mysqlconn; Const stringsql ="SELECT s,w from SW"; varresult =db. Executedatareader (SQL); Mysqlconnection Con=NewMysqlconnection ("server=012.345.678.910;port=0123; User id=userid;password=pwd;database=db"); Mysqldataadapter da=Newmysqldataadapter (sql, con); DataSet DS=NewDataSet (); Da. Fill (DS); DataTable DT= ds. tables[0];//get data from another database (MYSQL)//reading from the database varCategoryList =NewList<comm2viewmodel>(); for(inti =0; i < dt. Rows.Count; i++) {Categorylist.add (NewComm2viewmodel () {Id = dt. rows[i][0]. ToString (), Name = dt. rows[i][1]. ToString ()}); } _model.comm2list= CategoryList;//Fill #endregion varPageSize = request["pagesize"] ==NULL?Ten:int. Parse (request["pagesize"]); Oqlcompare Fun (Oqlcompare cmp, Users u) {cmp= Cmp.comparer (U.isdelete,"=",false); CMP= Cmp.comparer (U.status,"=",1);//users who have applied for certification returnCMP; } varTotal = Curd.getrecordcounts ((oqlcomparefunc<users>); _model. Userslist= OQL. Fromobject<users> (). Select (). Where (Fun). (o, b) = =O.desc (b.id)). Limit (pageSize, page, total). ToList (); Viewbag.paging= Paging.pagenavigate (pageSize, page, Total,""); Viewbag.msg=MSG; MSG=""; Viewbag.deleteurl="Address"; returnView (_model); }
View Views:
@model: /. Models.vipviewmodel <!--Here is a reference to the custom model, the address is actually changed to
<Tableclass= "Table"> <thead> <TR> <th>Id</th> <th>Company Name</th> <th>Position</th> <th>Certified Name</th> <th>Contact phone</th> <th>Community</th> <th>Room number</th> <th>Add date</th> <th>Operation</th> </TR> </thead> <tbody>@if (Model.UsersList.Count > 0) { foreach (var item in model.userslist) {<TR> <TD> <P>@item. Id</P> </TD> <TD> <P>@item. CompanyName</P> </TD> <TD> <P>@item. Type</P> </TD> <TD> <P>@item. Name</P> </TD> <TD> <P>@item. Phone</P> </TD> <TD>@{foreach (Var item2 in Mo Del. Comm2list) {if (item2.i D = = Item. Community2) { <P>@item2. Name</P>Break ; } } } </TD> <TD> <P>@item. Community</P> </TD> <TD> <P>@item. Createtime.tostring ("F")</P> </TD> <TD> <Divclass= "Operate"> <ahref=""class= "Gray">Through certification</a> <ahref= "javascript:;"class= "Red"onclick="">Reject authentication</a> </Div> </TD> </TR> } } </tbody> </Table>
Vipviewmodel: Public classVipviewmodel { PublicList<users> Userslist {Get;Set; }  PublicList<comm2viewmodel> Comm2list {Get;Set; } }comm2viewmodel: Public classComm2viewmodel { Public stringId {Get;Set; }  Public stringName {Get;Set; } }

Finally, attach the structure:

. NET MVC displays data from different databases (MSSQL, MySQL) with the same page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.