本文介绍了将数据集绑定到gridview。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我无法将数据集绑定到gridview。 以下是我的aspx和.vb代码 <%@ Page 语言 = VB AutoEventWireup = false CodeFile = BVAL_Prices.aspx.vb 继承 = BVAL_Prices %> < !DOCTYPE HTML PUBLIC - // W3C / / DTD HTML 4.0 Transitional // EN > < html > < head > < meta http-equiv = 内容类型 内容 = text / html; charset = utf-8 > < link href = ../../ styles / quicksite.css type = text / css rel = 样式表 > < link href = ../../ styles / chkBoxScroll.css rel = stylesheet 类型 = text / css / > < script src = ../ scripts / rwhitespace.js type = text / jscript > < / 脚本 > < / head > < BODY id = RWhitespaceBody onresize = rwhitespace_onresize() önload = rwhitespace_onload() style = padding-right:0; > < div class = RightPannel id = RightPannel > < div class = RightHeader id = RightHeader > BVAL价格< / div > < div class = RightPannelBody id = RightPannelBody > < table cellpadding = 5 cellspacing = 0 border = 0 bordercol或 = black width = 100%>< br mode = hold / > < tr > < td style = width:2 % > < / td > < td style = width:96% valign = top > <! - 内容到此处 - > < 表格 id = form1 runat = 服务器 > < div style = width:100%; height:40px;背景颜色:白色;边界:固体1#808080;填充:0 0 2 0; > < div class = RightHeader > < / div > < div style = padding:2 5 2 5; > < table id = 表1 宽度 = 100% cellpadding = 0 cellspacing = 0 runat = server > < tr > < td style = width:10% valign = Top > < asp:按钮 ID = btnAddSub runat = server 文本 = 添加/减去列 OnClientClick = ShowDiv();返回true / > < / td > < td 样式 = width:10% valign = top > < div id = dv runat = server visible = false style = overflow-Y:scroll;身高:100px; background-color:#FFFFFF;宽度:200px; > < asp:CheckBoxList ID = chkColumns runat = server AutoPostBack = true > < / td > < / tr > < / div > < / div > < / td > < td style = width:20% valign = top > < asp:按钮 ID = btnExportToExcel runat = server 文本 = 导出到Excel / > & nbsp; < / td > < / tr > < 表 width = 98% border = 0 cellspacing = 0 cellpadding = 0 > < tr > < td colspan = 2 > < asp: GridView ID = BVAL_Prices runat = server 可见 = true AutoGenerateColumns = False DataKeyNames = MR_SEC_ID BorderColor = #E7E7FF BorderWidth = 0px CellPadding = 3 GridLines = 垂直 Width = 98% > < 列 > < asp:BoundField HeaderText = MR SEC ID DataField = MR_SEC_ID 可见 = true / > < asp:BoundField HeaderText = STATE STREET CUSIP DataField = STATE_STREET_CUSIP 可见 = true / > ; < asp:BoundField HeaderText = BOND CUSIP DataField = BOND_CUSIP 可见 = true / > < asp:BoundField HeaderText = BLOOMBERG SECURITY ID DataField = BLOOMBERG_SECURITY_ID SortExpression = BLOOMBERG_SECURITY_ID 可见 = true / > < asp:BoundField HeaderText = BB UNIQUE DataField = BB_UNIQUE SortExpression = BB_UNIQUE 可见 = true / > < asp:BoundField HeaderText = 价格 DataField = 价格 SortExpression = 价格 可见 = true / > < / columns > < HeaderStyle 字体大小 = 10px BackColor = #dbd8d1 / > < alternatingrow style backcolor = #E7E7FF / > < / td > < / tr > < / table > < br / > $ b$b <!-- Block content goes here --> </div> </div> <br /> <asp:SqlDataSource ID=\"models_info\" runat=\"server\" ConnectionString=\"<%$ ConnectionStrings:oramrp1_conn %>\" ProviderName=\"<%$ ConnectionStrings:oramrp1_conn.ProviderName %>\" SelectCommand=\" select model_code,model_nme,comments_txt,Comments_Id from lam_pricing.model \"> </form> <td style=\"width: 2%\"> </td> </BODY></HTML> Below is my vb code Imports System.Timers Imports System.Data Imports System.Windows.Forms Imports IFC.Applications.PricingModel Imports PricingDatabase Imports PerSecurityWSDL Imports System.Security.Cryptography.X509Certificates Imports System.Collections.Generic Imports System.Web.UI Imports System.Web Imports System.Data.OracleClient Partial Class BVAL_Prices Inherits System.Web.UI.Page Private Shared aTimer As Sy stem.Timers.Timer Dim sbmtGetDataReq As PerSecurityWSDL.SubmitGetDataRequest = New PerSecurityWSDL.SubmitGetDataRequest() Dim sbmtGetDataRes As PerSecurityWSDL.SubmitGetDataResponse = New PerSecurityWSDL.SubmitGetDataResponse() Dim retGetDataRes As PerSecurityWSDL.RetrieveGetDataResponse = New PerSecurityWSDL.RetrieveGetDataResponse() Dim retGetDataReq As PerSecurityWSDL.RetrieveGetDataRequest = New PerSecurityWSDL.RetrieveGetDataRequest() Dim ps As PerSecurityWSDL.PerSecuri tyWS = New PerSecurityWSDL.PerSecurityWS() Dim getDataHeaders As PerSecurityWSDL.GetDataHeaders = New PerSecurityWSDL.GetDataHeaders() Public MaxHeight As Integer = 300 ''' <summary> ''' The width of the popup ''' </summary> Public Width As Integer = 200 Dim objDao As New DAO Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try If Not Page.IsPostBack Then bindBVALPrices() End If Catch ex As Exception End Try End Sub Public Sub bindBVALPrices() Try Dim certificatePath As String = System.Configuration.ConfigurationManager.AppSettings(\"BloombergCertificatePath\") Dim Password As String = System.Configuration.ConfigurationManager.AppSettings(\"BBPassword\") Dim clientCert As New X509Certificate2(certificatePath, Password) Dim strsqlBB As String = \"SELECT PSBM.MR_SEC_ID,PSBM.SECURITY_ID, PSBM.BB_UNIQUE FROM LAM_PRICING.PRICING_SECURITY_BB_MAPPING PSBM\" & _ \" WHERE PSBM.MR_SEC_ID IN (SELECT PSM.MR_SEC_ID FROM LAM_PRICING.PRICING_SECURITY_MASTER PSM\" & _ \" WHERE PSM.ACTIVE_IND = 'Y' AND PSM.ASSET_TYPE_CODE = 'BOND')\" Dim strconnection As String = ConfigurationManager.ConnectionStrings(\"oramrp1_conn\").ConnectionString Dim connection As New OracleConnection(strconnection) Dim cmd As New OracleCommand(strsqlBB, connection) Dim sqlDa As New OracleDataAdapter(cmd) Dim dsBB As DataSet = New DataSet sqlDa.Fill(dsBB) 'test.DataSource = dsBB 'test.DataBind() Dim icount As Integer = 0 icount = dsBB.Tables(0).Rows.Count - 1 Dim strbb(icount) As String 'SendLotus() ps.ClientCertificates.Add(clientCert) Dim instrumentBB(icount) As PerSecurityWSDL.Instrument Dim insBB As PerSecurityWSDL.Instruments = New PerSecurityWSDL.Instruments ' Dim fieldset As PerSecurityWSDL.BvalFieldSet = New PerSecurityWSDL.BvalFieldSet() If (dsBB.Tables(0) Is Nothing) Then 'MessageBox.Show(\"No BVAL Prices\") Else For iDsBBCount As Integer = 0 To dsBB.Tables(0).Rows.Count - 1 instrumentBB(iDsBBCount) = New Instrument instrumentBB(iDsBBCount).id = dsBB.Tables(0).Rows(iDsBBCount)(\"BB_UNIQUE\").ToString instrumentBB(iDsBBCount).type = InstrumentType.BB_UNIQUE instrumentBB(iDsBBCount).typeSpecified = True Next End If getDataHeaders.secmaster = True getDataHeaders.secmasterSpecified = True getDataHeaders.closingvalues = True getDataHeaders.closingvaluesSpecified = True getDataHeaders.derived = True getDataHeaders.derivedSpecified = True insBB.instrument = instrumentBB sbmtGetDataReq.headers = getDataHeaders sbmtGetDataReq.instruments = insBB sbmtGetDataReq.fields = New String() {\"PX_LAST\", \"ID_BB_UNIQUE\"} Try sbmtGetDataRes = ps.submitGetDataRequest(sbmtGetDataReq) retGetDataReq.responseId = sbmtGetDataRes.responseId retGetDataRes = ps.retrieveGetDataResponse(retGetDataReq) If retGetDataRes.statusCode.code = 100 Then aTimer = New System.Timers.Timer() ' Hook up the Elapsed event for the timer. AddHandler aTimer.Elapsed, AddressOf OnTimedEvent ' Set the Interval to 5 mins (300000 milliseconds). aTimer.Interval = 300000 aTimer.Enabled = True End If Catch ex As Exception End Try Catch ex As Exception End Try End Sub Public Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs) aTimer.Enabled = False aTimer.Stop() GetPrices() End Sub Public Sub GetPrices() Dim strsqlBB As String = \"SELECT PSBM.MR_SEC_ID, PSBM.STATE_STREET_CUSIP, PSBM.BOND_CUSIP, PS BM.BLOOMBERG_SECURITY_ID, PSBM.BB_UNIQUE FROM LAM_PRICING.PRICING_SECURITY_BB_MAPPING PSBM \" & _ \" WHERE PSBM.MR_SEC_ID IN (SELECT PSM.MR_SEC_ID FROM LAM_PRICING.PRICING_SECURITY_MASTER PSM\" & _ \" WHERE PSM.ACTIVE_IND = 'Y' AND PSM.ASSET_TYPE_CODE = 'BOND')\" Dim strconnection As String = ConfigurationManager.ConnectionStrings(\"oramrp1_conn\").ConnectionString Dim connection As New OracleConnection(strconnection) Dim cmd As New Orac leCommand(strsqlBB, connection) Dim sqlDa As New OracleDataAdapter(cmd) Dim dsBB As DataSet = New DataSet sqlDa.Fill(dsBB) Dim drBval As DataRow Dim dcBVal As DataColumn dcBVal = New DataColumn() Dim dtBval As DataTable = GetTable() Dim dsBval As DataSet = New DataSet retGetDataRes = ps.retrieveGetDataResponse(retGetDataReq) For Each dr As DataRow In dsBB.Tables(0).Rows For Each inst As InstrumentData In retGetDataRes.instrumentDatas If dr.Item(\"BB_UNIQUE\").ToString = inst.instrument.id.ToString Then drBval = dtBval.NewRow() drBval.Item(\"MR_SEC_ID\") = dr.Item(\"MR_SEC_ID\").ToString drBval.Item(\"STATE_STREET_CUSIP\") = dr.Item(\"STATE_STREET_CUSIP\").ToString drBval.Item(\"BOND_CUSIP\") = dr.Item(\"BOND_CUSIP\").ToString drBval.Item(\"BLOOMBERG_SECURITY_ID\") = dr.Item(\"BLOOMBERG_SECURITY_ID\").ToString drBval.Item(\"BB_UNIQUE\") = dr.Item(\"BB_UNIQUE\").ToString drBval.Item(\"Prices\") = inst.data(0).value.ToString dtBval.Rows.Add(drBval) End If Next Next dsBval.Tables.Add(dtBval) BVAL_Prices.DataSource = dsBval BVAL_Prices.DataBind() BVAL_Prices.Visible = True End Sub Public Function GetTable() As DataTable Dim dtTable As DataTable dtTable = New DataTable dtTable.Columns.Add(\"MR_SEC_ID\" , GetType(String)) dtTable.Columns.Add(\"STATE_STREET_CUSIP\", GetType(String)) dtTable.Columns.Add(\"BOND_CUSIP\", GetType(String)) dtTable.Columns.Add(\"BLOOMBERG_SECURITY_ID\", GetType(String)) dtTable.Columns.Add(\"BB_UNIQUE\", GetType(String)) dtTable.Columns.Add(\"Pri ces\", GetType(String)) Return dtTable End Function End Class 解决方案 ConnectionStrings:oramrp1_conn %>\" ProviderName=\"<%ConnectionStrings:oramrp1_conn.ProviderName %>\" SelectCommand=\" select model_code,model_nme,comments_txt,Comments_Id $b$ b from lam_pricing.model \"> </form> <td style=\"width: 2%\"> </td> </BODY></HTML> Below is my vb code Imports System.Timers Imports System.Data Imports System.Windows.Forms Imports IFC.Applications.PricingModel Imports PricingDatabase Imports PerSecurityWSDL Imports System.Security.Cryptography.X509Certificates Imports System.Collections.Generic Imports System.Web.UI Imports System.Web Imports System.Data.OracleClient Partial Class BVAL_Prices Inherits System.Web.UI.Page Private Shared aTimer As System.Timers.Timer Dim sbmtGetDataReq As PerSecurityWSDL.SubmitGetDataRequest = New PerSecurityWSDL.SubmitGetDataRequest() Dim sbmtGetDataRes As PerSecurityWSDL.SubmitGetDataResponse = New PerSecurityWSDL.SubmitGetDataResponse() Dim retGetDataRes As PerSecurityWSDL.RetrieveGetDataResponse = New PerSecurityWSDL.RetrieveGetDataResponse() Dim retGetDataReq As PerSecurityWSDL.RetrieveGetDataRequest = New PerSecurityWSDL.RetrieveGetDataRequest() Dim ps As PerSecurityWSDL.PerSecurityWS = New PerSecurityWSDL.PerSecurityWS() Dim getDataHeaders As PerSecurityWSDL.GetDataHeaders = New PerSecurityWSDL.GetDataHeaders() Public MaxHeight As Integer = 300 ''' <summary> ''' The width of the popup ''' </summary> Public Width As Integer = 200 Dim objDao As New DAO Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try I f Not Page.IsPostBack Then bindBVALPrices() End If Catch ex As Exception End Try End Sub Public Sub bindBVALPrices() Try Dim certificatePath As String = System.Configuration.ConfigurationManager.AppSettings(\"Bloo mbergCertificatePath\") Dim Password As String = System.Configuration.ConfigurationManager.AppSettings(\"BBPassword\") Dim clientCert As New X509Certificate2(certificatePath, Password) Dim strsqlBB As String = \"SELECT PSBM.MR_SEC_ID,PSBM.SECURITY_ID, PSBM.BB_UNIQUE FROM LAM_PRICING.PRICING_SECURITY_BB_MAPPING PSBM\" & _ \" WHERE PSBM.MR_SEC_ID IN (SELECT PSM.MR_SEC_ID FROM LAM_PRICING.PRICING_SECURITY_MASTER PSM\" & _ \" WHERE PSM.ACTIVE_IND = 'Y' AND PSM.ASSET_TYPE_CODE = 'BOND')\" Dim strconnection As String = ConfigurationManager.ConnectionStrings(\"oramrp1_conn\").ConnectionString Dim connection As New OracleConnection(strconnection) Dim cmd As New OracleCommand(strsqlBB, connection) Dim sqlDa As New OracleDataAdapter(cmd) Dim dsBB As DataSet = New DataSet sqlDa.Fill(dsBB) 'test.DataSource = dsBB 'test.DataBind() Dim icount As Integer = 0 icount = dsBB.Tables(0).Rows.Count - 1 Dim strbb(icount) As String 'SendLotus() ps.ClientCertificates.Add(clientCert) Dim instrumentBB(icount) As PerSecurityWSDL.Instrument Dim insBB As PerSecurityWSDL.Instruments = New PerSecurityWSDL.Instruments ' Dim fieldset As PerSecurityWSDL.BvalFieldSet = New PerSecurityWSDL.BvalFieldSet() If (dsBB.Tables(0) Is Nothing) Then 'MessageBox.Show(\"No BVAL Prices\") Else For iDsBBCount As Integer = 0 To dsBB.Tables(0).Rows.Count - 1 instrumentBB(iDsBBCount) = New Instrument instrumentBB(iDsBBCount).id = dsBB.Tables(0).Rows(iDsBBCount)(\"BB_UNIQUE\").ToString instrumentBB(iDsBBCount).type = InstrumentType.BB_UNIQUE instrumentBB(iDsBBCount).typeSpecified = True Next End If getDataHeaders.secmaster = True getDataHeaders.secmasterSpecified = True getDataHeaders.closingvalues = True getDataHeaders.closingvaluesSpecified = True getDataHeaders.derived = True getDataHeaders.derivedSpecified = True insBB.instrument = instrumentBB sbmtGetDataReq.headers = getDataHeaders sbmtGetDataReq.instruments = insBB sbmtGetDataReq.fields = New String() {\"PX_LAST\", \"ID_BB_UNIQUE\"} Try sbmtGetDataRes = ps.submitGetDataRequest(sbmtGetDataReq) retGetDataReq.responseId = sbmtGetDataRes.responseId retGetDataRes = ps.retrieveGetDataResponse(retGetDataReq) If retGetDataRes.statusCode.code = 100 Then aTimer = New System.Timers.Timer() ' Hook up the Elapsed event for the timer. AddHandler aTimer.Elapsed, AddressOf OnTimedEvent ' Set the Interval to 5 mins (300000 milliseconds). aTimer.Interval = 300000 aTimer.Enabled = True End If Catch ex As Exception End Try Catch ex As Exception End Try End Sub Public Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs) aTimer.Enabled = False aTimer.Stop() GetPrices() End Sub Public Sub GetPrices() Dim strsqlBB As String = \"SELECT PSBM.MR_SEC_ID, PSBM.STATE_STREET_CUSIP, PSBM.BOND_CUSIP, PS BM.BLOOMBERG_SECURITY_ID, PSBM.BB_UNIQUE FROM LAM_PRICING.PRICING_SECURITY_BB_MAPPING PSBM \" & _ \" WHERE PSBM.MR_SEC_ID IN (SELECT PSM.MR_SEC_ID FROM LAM_PRICING.PRICING_SECURITY_MASTER PSM\" & _ \" WHERE PSM.ACTIVE_IND = 'Y' AND PSM.ASSET_TYPE_CODE = 'BOND')\" Dim strconnection As String = ConfigurationManager.ConnectionStrings(\"oramrp1_conn\").ConnectionString Dim connection As New OracleConnection(strconnection) Dim cmd As New Orac leCommand(strsqlBB, connection) Dim sqlDa As New OracleDataAdapter(cmd) Dim dsBB As DataSet = New DataSet sqlDa.Fill(dsBB) Dim drBval As DataRow Dim dcBVal As DataColumn dcBVal = New DataColumn() Dim dtBval As DataTable = GetTable() Dim dsBval As DataSet = New DataSet retGetDataRes = ps.retrieveGetDataResponse(retGetDataReq) For Each dr As DataRow In dsBB.Tables(0).Rows For Each inst As InstrumentData In retGetDataRes.instrumentDatas If dr.Item(\"BB_UNIQUE\").ToString = inst.instrument.id.ToString Then drBval = dtBval.NewRow() drBval.Item(\"MR_SEC_ID\") = dr.Item(\"MR_SEC_ID\").ToString drBval.Item(\"STATE_STREET_CUSIP\") = dr.Item(\"STATE_STREET_CUSIP\").ToString drBval.Item(\"BOND_CUSIP\") = dr.Item(\"BOND_CUSIP\").ToString drBval.Item(\"BLOOMBERG_SECURITY_ID\") = dr.Item(\"BLOOMBERG_SECURITY_ID\").ToString drBval.Item(\"BB_UNIQUE\") = dr.Item(\"BB_UNIQUE\").ToString drBval.Item(\"Prices\") = inst.data(0).value.ToString dtBval.Rows.Add(drBval) End If Next Next dsBval.Tables.Add(dtBval) BVAL_Prices.DataSource = dsBval BVAL_Prices.DataBind() BVAL_Prices.Visible = True End Sub Public Function GetTable() As DataTable Dim dtTable As DataTable dtTable = New DataTable dtTable.Columns.Add(\"MR_SEC_ID\" , GetType(String)) dtTable.Columns.Add(\"STATE_STREET_CUSIP\", GetType(String)) dtTable.Columns.Add(\"BOND_CUSIP\", GetType(String)) dtTable.Columns.Add(\"BLOOMBERG_SECURITY_ID\", GetType(String)) dtTable.Columns.Add(\"BB_UNIQUE\", GetType(String)) dtTable.Columns.Add(\"Pri ces\", GetType(String)) Return dtTable End Function End ClassYou should either bind a datatable to a Gridview or when you bind a dataset, then you should tell the Gridview which datatable it should be bound to.... DataGridView1.AutoGenerateColumns = True; DataGridView1.DataSource = ds; // dataset DataGridView1.DataMember = \"TableName\"; Hi,Am not able to bind the dataset to the gridview.below are my aspx and .vb code<%@ Page Language="VB" AutoEventWireup="false"CodeFile="BVAL_Prices.aspx.vb" Inherits="BVAL_Prices" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><link href="../../styles/quicksite.css" type="text/css" rel="stylesheet"><link href="../../styles/chkBoxScroll.css" rel="stylesheet" type="text/css" /><script src="../scripts/rwhitespace.js" type ="text/jscript" ></script></head><BODY id=RWhitespaceBody onresize=rwhitespace_onresize() önload=rwhitespace_onload() style="padding-right:0;"><div class="RightPannel" id="RightPannel"><div class="RightHeader" id="RightHeader">BVAL Prices</div><div class="RightPannelBody" id="RightPannelBody"> <table cellpadding="5" cellspacing="0" border="0" bordercolor="black" width="100%><br" mode="hold" /> <tr> <td style="width: 2%"> </td> <td style="width: 96%" valign="top"> <!-- content goes here--> <form id="form1" runat="server" > <div style="width: 100%;height:40px; background-color:white; border:solid 1 #808080; padding: 0 0 2 0;"> <div class="RightHeader"> </div> <div style="padding: 2 5 2 5;"> <table id="Table1" width="100%" cellpadding="0" cellspacing="0" runat="server"> <tr> <td style="width:10%" valign="Top"> <asp:Button ID="btnAddSub" runat="server" Text="Add/Subtract Columns" OnClientClick="ShowDiv(); return true" /> </td> <td style="width:10%" valign="top"> <div id ="dv" runat="server" visible="false" style="overflow-Y: scroll; height: 100px; background-color: #FFFFFF; width: 200px;"> <asp:CheckBoxList ID = "chkColumns" runat="server" AutoPostBack="true"> </td></tr></div> </div></td> <td style="width:20%" valign="top"> <asp:Button ID="btnExportToExcel" runat="server" Text="Export To Excel" /> </td> </tr> <table width="98%" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2"> <asp:GridView ID="BVAL_Prices" runat="server" Visible="true" AutoGenerateColumns="False" DataKeyNames="MR_SEC_ID" BorderColor="#E7E7FF" BorderWidth="0px" CellPadding="3" GridLines="Vertical" Width="98%"> <columns> <asp:BoundField HeaderText="MR SEC ID" DataField="MR_SEC_ID" Visible ="true"/> <asp:BoundField HeaderText="STATE STREET CUSIP" DataField="STATE_STREET_CUSIP" Visible ="true"/> <asp:BoundField HeaderText="BOND CUSIP" DataField="BOND_CUSIP" Visible ="true"/> <asp:BoundField HeaderText="BLOOMBERG SECURITY ID" DataField="BLOOMBERG_SECURITY_ID" SortExpression="BLOOMBERG_SECURITY_ID" Visible ="true"/> <asp:BoundField HeaderText="BB UNIQUE" DataField="BB_UNIQUE" SortExpression="BB_UNIQUE" Visible ="true"/> <asp:BoundField HeaderText="Prices" DataField="Prices" SortExpression="Prices" Visible ="true"/> </columns> <HeaderStyle Font-Size="10px" BackColor="#dbd8d1" /> <alternatingrowstyle backcolor="#E7E7FF" /> </td> </tr> </table> <br /> <!-- Block content goes here--> </div> </div> <br /> <asp:SqlDataSource ID="models_info" runat="server" ConnectionString="<%$ ConnectionStrings:oramrp1_conn %>" ProviderName="<%$ ConnectionStrings:oramrp1_conn.ProviderName %>" SelectCommand="select model_code,model_nme,comments_txt,Comments_Idfrom lam_pricing.model "> </form> <td style="width: 2%"> </td></BODY></HTML>Below is my vb codeImports System.TimersImports System.DataImports System.Windows.FormsImports IFC.Applications.PricingModelImports PricingDatabaseImports PerSecurityWSDLImports System.Security.Cryptography.X509CertificatesImports System.Collections.GenericImports System.Web.UIImports System.WebImports System.Data.OracleClientPartial Class BVAL_Prices Inherits System.Web.UI.Page Private Shared aTimer As System.Timers.Timer Dim sbmtGetDataReq As PerSecurityWSDL.SubmitGetDataRequest = New PerSecurityWSDL.SubmitGetDataRequest() Dim sbmtGetDataRes As PerSecurityWSDL.SubmitGetDataResponse = New PerSecurityWSDL.SubmitGetDataResponse() Dim retGetDataRes As PerSecurityWSDL.RetrieveGetDataResponse = New PerSecurityWSDL.RetrieveGetDataResponse() Dim retGetDataReq As PerSecurityWSDL.RetrieveGetDataRequest = New PerSecurityWSDL.RetrieveGetDataRequest() Dim ps As PerSecurityWSDL.PerSecurityWS = New PerSecurityWSDL.PerSecurityWS() Dim getDataHeaders As PerSecurityWSDL.GetDataHeaders = New PerSecurityWSDL.GetDataHeaders() Public MaxHeight As Integer = 300 ''' <summary> ''' The width of the popup ''' </summary> Public Width As Integer = 200 Dim objDao As New DAO Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try If Not Page.IsPostBack Then bindBVALPrices() End If Catch ex As Exception End Try End Sub Public Sub bindBVALPrices() Try Dim certificatePath As String = System.Configuration.ConfigurationManager.AppSettings("BloombergCertificatePath") Dim Password As String = System.Configuration.ConfigurationManager.AppSettings("BBPassword") Dim clientCert As New X509Certificate2(certificatePath, Password) Dim strsqlBB As String = "SELECT PSBM.MR_SEC_ID,PSBM.SECURITY_ID, PSBM.BB_UNIQUE FROM LAM_PRICING.PRICING_SECURITY_BB_MAPPING PSBM" & _ " WHERE PSBM.MR_SEC_ID IN (SELECT PSM.MR_SEC_ID FROM LAM_PRICING.PRICING_SECURITY_MASTER PSM" & _ " WHERE PSM.ACTIVE_IND = 'Y' AND PSM.ASSET_TYPE_CODE = 'BOND')" Dim strconnection As String = ConfigurationManager.ConnectionStrings("oramrp1_conn").ConnectionString Dim connection As New OracleConnection(strconnection) Dim cmd As New OracleCommand(strsqlBB, connection) Dim sqlDa As New OracleDataAdapter(cmd) Dim dsBB As DataSet = New DataSet sqlDa.Fill(dsBB) 'test.DataSource = dsBB 'test.DataBind() Dim icount As Integer = 0 icount = dsBB.Tables(0).Rows.Count - 1 Dim strbb(icount) As String 'SendLotus() ps.ClientCertificates.Add(clientCert) Dim instrumentBB(icount) As PerSecurityWSDL.Instrument Dim insBB As PerSecurityWSDL.Instruments = New PerSecurityWSDL.Instruments ' Dim fieldset As PerSecurityWSDL.BvalFieldSet = New PerSecurityWSDL.BvalFieldSet() If (dsBB.Tables(0) Is Nothing) Then 'MessageBox.Show("No BVAL Prices") Else For iDsBBCount As Integer = 0 To dsBB.Tables(0).Rows.Count - 1 instrumentBB(iDsBBCount) = New Instrument instrumentBB(iDsBBCount).id = dsBB.Tables(0).Rows(iDsBBCount)("BB_UNIQUE").ToString instrumentBB(iDsBBCount).type = InstrumentType.BB_UNIQUE instrumentBB(iDsBBCount).typeSpecified = True Next End If getDataHeaders.secmaster = True getDataHeaders.secmasterSpecified = True getDataHeaders.closingvalues = True getDataHeaders.closingvaluesSpecified = True getDataHeaders.derived = True getDataHeaders.derivedSpecified = True insBB.instrument = instrumentBB sbmtGetDataReq.headers = getDataHeaders sbmtGetDataReq.instruments = insBB sbmtGetDataReq.fields = New String() {"PX_LAST", "ID_BB_UNIQUE"} Try sbmtGetDataRes = ps.submitGetDataRequest(sbmtGetDataReq) retGetDataReq.responseId = sbmtGetDataRes.responseId retGetDataRes = ps.retrieveGetDataResponse(retGetDataReq) If retGetDataRes.statusCode.code = 100 Then aTimer = New System.Timers.Timer() ' Hook up the Elapsed event for the timer. AddHandler aTimer.Elapsed, AddressOf OnTimedEvent ' Set the Interval to 5 mins (300000 milliseconds). aTimer.Interval = 300000 aTimer.Enabled = True End If Catch ex As Exception End Try Catch ex As Exception End Try End Sub Public Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs) aTimer.Enabled = False aTimer.Stop() GetPrices() End Sub Public Sub GetPrices() Dim strsqlBB As String = "SELECT PSBM.MR_SEC_ID, PSBM.STATE_STREET_CUSIP, PSBM.BOND_CUSIP, PSBM.BLOOMBERG_SECURITY_ID, PSBM.BB_UNIQUE FROM LAM_PRICING.PRICING_SECURITY_BB_MAPPING PSBM " & _ " WHERE PSBM.MR_SEC_ID IN (SELECT PSM.MR_SEC_ID FROM LAM_PRICING.PRICING_SECURITY_MASTER PSM" & _ " WHERE PSM.ACTIVE_IND = 'Y' AND PSM.ASSET_TYPE_CODE = 'BOND')" Dim strconnection As String = ConfigurationManager.ConnectionStrings("oramrp1_conn").ConnectionString Dim connection As New OracleConnection(strconnection) Dim cmd As New OracleCommand(strsqlBB, connection) Dim sqlDa As New OracleDataAdapter(cmd) Dim dsBB As DataSet = New DataSet sqlDa.Fill(dsBB) Dim drBval As DataRow Dim dcBVal As DataColumn dcBVal = New DataColumn() Dim dtBval As DataTable = GetTable() Dim dsBval As DataSet = New DataSet retGetDataRes = ps.retrieveGetDataResponse(retGetDataReq) For Each dr As DataRow In dsBB.Tables(0).Rows For Each inst As InstrumentData In retGetDataRes.instrumentDatas If dr.Item("BB_UNIQUE").ToString = inst.instrument.id.ToString Then drBval = dtBval.NewRow() drBval.Item("MR_SEC_ID") = dr.Item("MR_SEC_ID").ToString drBval.Item("STATE_STREET_CUSIP") = dr.Item("STATE_STREET_CUSIP").ToString drBval.Item("BOND_CUSIP") = dr.Item("BOND_CUSIP").ToString drBval.Item("BLOOMBERG_SECURITY_ID") = dr.Item("BLOOMBERG_SECURITY_ID").ToString drBval.Item("BB_UNIQUE") = dr.Item("BB_UNIQUE").ToString drBval.Item("Prices") = inst.data(0).value.ToString dtBval.Rows.Add(drBval) End If Next Next dsBval.Tables.Add(dtBval) BVAL_Prices.DataSource = dsBval BVAL_Prices.DataBind() BVAL_Prices.Visible = True End Sub Public Function GetTable() As DataTable Dim dtTable As DataTable dtTable = New DataTable dtTable.Columns.Add("MR_SEC_ID", GetType(String)) dtTable.Columns.Add("STATE_STREET_CUSIP", GetType(String)) dtTable.Columns.Add("BOND_CUSIP", GetType(String)) dtTable.Columns.Add("BLOOMBERG_SECURITY_ID", GetType(String)) dtTable.Columns.Add("BB_UNIQUE", GetType(String)) dtTable.Columns.Add("Prices", GetType(String)) Return dtTable End FunctionEnd Class 解决方案 ConnectionStrings:oramrp1_conn %>" ProviderName="<%ConnectionStrings:oramrp1_conn.ProviderName %>" SelectCommand="select model_code,model_nme,comments_txt,Comments_Idfrom lam_pricing.model "> </form> <td style="width: 2%"> </td></BODY></HTML>Below is my vb codeImports System.TimersImports System.DataImports System.Windows.FormsImports IFC.Applications.PricingModelImports PricingDatabaseImports PerSecurityWSDLImports System.Security.Cryptography.X509CertificatesImports System.Collections.GenericImports System.Web.UIImports System.WebImports System.Data.OracleClientPartial Class BVAL_Prices Inherits System.Web.UI.Page Private Shared aTimer As System.Timers.Timer Dim sbmtGetDataReq As PerSecurityWSDL.SubmitGetDataRequest = New PerSecurityWSDL.SubmitGetDataRequest() Dim sbmtGetDataRes As PerSecurityWSDL.SubmitGetDataResponse = New PerSecurityWSDL.SubmitGetDataResponse() Dim retGetDataRes As PerSecurityWSDL.RetrieveGetDataResponse = New PerSecurityWSDL.RetrieveGetDataResponse() Dim retGetDataReq As PerSecurityWSDL.RetrieveGetDataRequest = New PerSecurityWSDL.RetrieveGetDataRequest() Dim ps As PerSecurityWSDL.PerSecurityWS = New PerSecurityWSDL.PerSecurityWS() Dim getDataHeaders As PerSecurityWSDL.GetDataHeaders = New PerSecurityWSDL.GetDataHeaders() Public MaxHeight As Integer = 300 ''' <summary> ''' The width of the popup ''' </summary> Public Width As Integer = 200 Dim objDao As New DAO Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try If Not Page.IsPostBack Then bindBVALPrices() End If Catch ex As Exception End Try End Sub Public Sub bindBVALPrices() Try Dim certificatePath As String = System.Configuration.ConfigurationManager.AppSettings("BloombergCertificatePath") Dim Password As String = System.Configuration.ConfigurationManager.AppSettings("BBPassword") Dim clientCert As New X509Certificate2(certificatePath, Password) Dim strsqlBB As String = "SELECT PSBM.MR_SEC_ID,PSBM.SECURITY_ID, PSBM.BB_UNIQUE FROM LAM_PRICING.PRICING_SECURITY_BB_MAPPING PSBM" & _ " WHERE PSBM.MR_SEC_ID IN (SELECT PSM.MR_SEC_ID FROM LAM_PRICING.PRICING_SECURITY_MASTER PSM" & _ " WHERE PSM.ACTIVE_IND = 'Y' AND PSM.ASSET_TYPE_CODE = 'BOND')" Dim strconnection As String = ConfigurationManager.ConnectionStrings("oramrp1_conn").ConnectionString Dim connection As New OracleConnection(strconnection) Dim cmd As New OracleCommand(strsqlBB, connection) Dim sqlDa As New OracleDataAdapter(cmd) Dim dsBB As DataSet = New DataSet sqlDa.Fill(dsBB) 'test.DataSource = dsBB 'test.DataBind() Dim icount As Integer = 0 icount = dsBB.Tables(0).Rows.Count - 1 Dim strbb(icount) As String 'SendLotus() ps.ClientCertificates.Add(clientCert) Dim instrumentBB(icount) As PerSecurityWSDL.Instrument Dim insBB As PerSecurityWSDL.Instruments = New PerSecurityWSDL.Instruments ' Dim fieldset As PerSecurityWSDL.BvalFieldSet = New PerSecurityWSDL.BvalFieldSet() If (dsBB.Tables(0) Is Nothing) Then 'MessageBox.Show("No BVAL Prices") Else For iDsBBCount As Integer = 0 To dsBB.Tables(0).Rows.Count - 1 instrumentBB(iDsBBCount) = New Instrument instrumentBB(iDsBBCount).id = dsBB.Tables(0).Rows(iDsBBCount)("BB_UNIQUE").ToString instrumentBB(iDsBBCount).type = InstrumentType.BB_UNIQUE instrumentBB(iDsBBCount).typeSpecified = True Next End If getDataHeaders.secmaster = True getDataHeaders.secmasterSpecified = True getDataHeaders.closingvalues = True getDataHeaders.closingvaluesSpecified = True getDataHeaders.derived = True getDataHeaders.derivedSpecified = True insBB.instrument = instrumentBB sbmtGetDataReq.headers = getDataHeaders sbmtGetDataReq.instruments = insBB sbmtGetDataReq.fields = New String() {"PX_LAST", "ID_BB_UNIQUE"} Try sbmtGetDataRes = ps.submitGetDataRequest(sbmtGetDataReq) retGetDataReq.responseId = sbmtGetDataRes.responseId retGetDataRes = ps.retrieveGetDataResponse(retGetDataReq) If retGetDataRes.statusCode.code = 100 Then aTimer = New System.Timers.Timer() ' Hook up the Elapsed event for the timer. AddHandler aTimer.Elapsed, AddressOf OnTimedEvent ' Set the Interval to 5 mins (300000 milliseconds). aTimer.Interval = 300000 aTimer.Enabled = True End If Catch ex As Exception End Try Catch ex As Exception End Try End Sub Public Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs) aTimer.Enabled = False aTimer.Stop() GetPrices() End Sub Public Sub GetPrices() Dim strsqlBB As String = "SELECT PSBM.MR_SEC_ID, PSBM.STATE_STREET_CUSIP, PSBM.BOND_CUSIP, PSBM.BLOOMBERG_SECURITY_ID, PSBM.BB_UNIQUE FROM LAM_PRICING.PRICING_SECURITY_BB_MAPPING PSBM " & _ " WHERE PSBM.MR_SEC_ID IN (SELECT PSM.MR_SEC_ID FROM LAM_PRICING.PRICING_SECURITY_MASTER PSM" & _ " WHERE PSM.ACTIVE_IND = 'Y' AND PSM.ASSET_TYPE_CODE = 'BOND')" Dim strconnection As String = ConfigurationManager.ConnectionStrings("oramrp1_conn").ConnectionString Dim connection As New OracleConnection(strconnection) Dim cmd As New OracleCommand(strsqlBB, connection) Dim sqlDa As New OracleDataAdapter(cmd) Dim dsBB As DataSet = New DataSet sqlDa.Fill(dsBB) Dim drBval As DataRow Dim dcBVal As DataColumn dcBVal = New DataColumn() Dim dtBval As DataTable = GetTable() Dim dsBval As DataSet = New DataSet retGetDataRes = ps.retrieveGetDataResponse(retGetDataReq) For Each dr As DataRow In dsBB.Tables(0).Rows For Each inst As InstrumentData In retGetDataRes.instrumentDatas If dr.Item("BB_UNIQUE").ToString = inst.instrument.id.ToString Then drBval = dtBval.NewRow() drBval.Item("MR_SEC_ID") = dr.Item("MR_SEC_ID").ToString drBval.Item("STATE_STREET_CUSIP") = dr.Item("STATE_STREET_CUSIP").ToString drBval.Item("BOND_CUSIP") = dr.Item("BOND_CUSIP").ToString drBval.Item("BLOOMBERG_SECURITY_ID") = dr.Item("BLOOMBERG_SECURITY_ID").ToString drBval.Item("BB_UNIQUE") = dr.Item("BB_UNIQUE").ToString drBval.Item("Prices") = inst.data(0).value.ToString dtBval.Rows.Add(drBval) End If Next Next dsBval.Tables.Add(dtBval) BVAL_Prices.DataSource = dsBval BVAL_Prices.DataBind() BVAL_Prices.Visible = True End Sub Public Function GetTable() As DataTable Dim dtTable As DataTable dtTable = New DataTable dtTable.Columns.Add("MR_SEC_ID", GetType(String)) dtTable.Columns.Add("STATE_STREET_CUSIP", GetType(String)) dtTable.Columns.Add("BOND_CUSIP", GetType(String)) dtTable.Columns.Add("BLOOMBERG_SECURITY_ID", GetType(String)) dtTable.Columns.Add("BB_UNIQUE", GetType(String)) dtTable.Columns.Add("Prices", GetType(String)) Return dtTable End FunctionEnd ClassYou should either bind a datatable to a Gridview or when you bind a dataset, then you should tell the Gridview which datatable it should be bound to....DataGridView1.AutoGenerateColumns = True;DataGridView1.DataSource = ds; // datasetDataGridView1.DataMember = "TableName"; 这篇关于将数据集绑定到gridview。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 21:14