如何替换数据集中的字符? [英] How do I replace characters within a dataset?

查看:83
本文介绍了如何替换数据集中的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用示例代码,该代码用于在运行iis8的2008 R2文件服务器上显示Microsoft Index Service的内容。问题是,我需要使用Replace函数将C:和\字符替换为使用Intranet的路径中的http://和/。我似乎无法弄清楚如何做到这一点,因为我继续得到错误,对这种语言一无所知,我已经阅读了好几天,什么都找不到。我希望我能够开始学习整个语言,而不是用所有的点点滴滴污染我的思想。请帮忙!!!比较感谢,比尔





这是VB代码:



Hello, I am using example code that works to display the contents of the Microsoft Index Service on our 2008 R2 File Server running iis8. Problem is, I need to use the Replace function to replace the "C:" and the "\" characters with "http://" and "/" in the path to work with the Intranet. I can't seem to figure out how to do that as I continue to get errors and knowing nothing about this language, I have been reading for days and can find nothing. I'm wishing I would have just started to learn the entire language instead of polluting my mind with all the bits and pieces. HELP PLEASE!!! Thank you in advance, Bill


Here is the VB code:

Imports System.Data

Partial Class _WebForm1
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strCatalog As String

        ' Catalog Name
        strCatalog = "IIS_Index"

        Dim strQuery As String
        strQuery = "Select DocTitle,Filename,Create,Size,Path,URL from SCOPE() where FREETEXT('" & TextBox1.Text & "')"
    Dim connString As String = "Provider=MSIDXS.1;Integrated Security .='';Data Source='" & strCatalog & "'"

        Dim cn As New System.Data.OleDb.OleDbConnection(connString)
        Dim cmd As New System.Data.OleDb.OleDbDataAdapter(strQuery, cn)
        Dim testDataSet As New DataSet()

        cmd.Fill(testDataSet)

        ' Bind DataGrid to the DataSet. DataGrid is the ID for the
        ' DataGrid control in the HTML section.
        Dim source As New DataView(testDataSet.Tables(0))
        DataGrid1.DataSource = source
        DataGrid1.DataBind()
    End Sub
End Class





这是HTML





Here is the HTML

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="search.aspx.vb" Inherits="_WebForm1"debug="true" %>

<HTML>
<HEAD>
<title>Intranet Index Services</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

</HEAD>
<body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
        <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 238px; POSITION: absolute; TOP: 76px" runat="server"></asp:TextBox>
        <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 25px; POSITION: absolute; TOP: 145px" runat="server" AutoGenerateColumns="False">

    <Columns>
        <asp:BoundColumn DataField="DocTitle" HeaderText="DocTitle"></asp:BoundColumn>
        <asp:BoundColumn DataField="filename" HeaderText="FileName"></asp:BoundColumn>
	<asp:BoundColumn DataField="Create" HeaderText="Create"></asp:BoundColumn>
        <asp:BoundColumn DataField="size" HeaderText="Size"></asp:BoundColumn>
        <asp:BoundColumn DataField="path" HeaderText="PATH"></asp:BoundColumn>
	<asp:BoundColumn DataField="url" HeaderText="URL "></asp:BoundColumn>
    </Columns>
		</asp:DataGrid>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 400px; POSITION: absolute; TOP: 100px" runat="server" Text="Button"></asp:Button>
<hr style="Z-INDEX: 104; LEFT: 0px; POSITION: absolute; TOP: 140px">
</form>
</body>
</HTML>

推荐答案

1.您可以通过在select语句中编写replace sql来从数据源中选择数据时进行替换。但是在oledb替换函数中不可用,因此您可能需要使用InStr()和Len实现替换( )函数。



2.您可以使用简单的for循环更改数据集或数据表列值,并使用字符串替换 [ ^ ]。然后将更新的数据表绑定到gridview



3.您可以使用GridView的RowDataBound事件并更改后更改设置单元格值。检查这个 [ ^ ]根据您的需要进行回答和修改。



我没有直接回答你的问题,你需要尝试自己并找到自己的解决方案。如果出现问题,你最好问一下你尝试过的问题以及你遇到的问题。祝你好运!
1. You can do the replace when you select data from your data source by writing replace sql in your select statement. but in oledb replace function not available, so you may need to implement replace using InStr() and Len() functions.

2. You can change the dataset or datatable column values by using simple for loop and change the values using string replace[^]. then bind the updated datatable to your gridview

3. you can use RowDataBound Event of your GridView and change set the cell value after replacing. check this [^] answer and modify according to your needs.

I haven't provide direct answer to your question, you need to try your self and find your own solution. in case of issue you better ask question with what you have tried and where you stuck. good luck!


这篇关于如何替换数据集中的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆