"' GO'"插入值时

时间:2015-08-19 18:47:39

标签: c# sql ssms

我收到上述错误。 我使用这段代码:

<Window x:Class="Opt.ExpertSystem.View.WindowPasteRules"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        xmlns:scroll="clr-namespace:Opt.ExpertSystem.View"
        Title="Paste Rules Options"  Width="400" Height="300">
    <Window.InputBindings>
        <KeyBinding Key="Esc" Command="{Binding CancelCommand}" />
    </Window.InputBindings>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="28"/>
            <RowDefinition Height="100*"/>

            <RowDefinition Height="35"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="76*" />
        </Grid.ColumnDefinitions>

        <Label Content="Select Rules to Paste: " Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" HorizontalContentAlignment="Right" Margin="0,0,2,0" Width="Auto"/>

        <Grid Grid.Row="1" Grid.ColumnSpan="2"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
            <Grid.Resources>
                <Style TargetType="ScrollViewer">
                    <Setter Property="scroll:ScrollSynchronizer.ScrollGroup" Value="Group1" />
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="50*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="5" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Label Content="Replace" HorizontalAlignment="Stretch" FontWeight="Bold"/>
            <TextBox Margin="55,2,2,2" Text="{Binding CopyNameOrigin}" ToolTip="Non-editable field. Represents the text you want to replace." Focusable="False"/>
            <Label Content="With" Grid.Column="2" HorizontalAlignment="Stretch" FontWeight="Bold"/>
            <TextBox Grid.Column="2" Margin="42,2,2,2" Text="{Binding CopyNameNew, UpdateSourceTrigger=PropertyChanged}" ToolTip="Represents the results of the changes to be made." />
            <ListBox ItemsSource="{Binding Path=CopiedRules}" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" BorderThickness="1" BorderBrush="CornflowerBlue" Grid.IsSharedSizeScope="True" Margin="2,0,2,10" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Label Content="{Binding Name}" />    
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <ListBox ItemsSource="{Binding Path=PasteRules}" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="2" BorderThickness="1" BorderBrush="CornflowerBlue"  Margin="2,0,2,10" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <CheckBox Content="{Binding Name}" IsChecked="{Binding IsChecked}" Margin="2,5,2,5" />             
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

        <Grid Grid.Row="2" Background="#FFECE9D8" Grid.ColumnSpan="2">
            <Button Content="OK" x:Name="btnOK" IsEnabled="{Binding IsValid, UpdateSourceTrigger=PropertyChanged}" Margin="0,6,6,0" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Height="23" Click="btnOK_Click" />
            <Button Content="Cancel" x:Name="btnCancel" IsCancel="True" Margin="0,6,90,0" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Height="23" />
        </Grid>
    </Grid>
</Window>

我使用SSMS编写了表格的内容,因此我得到了一个包含大量“INSERT INTO”的文件。声明和一些“GO&#39;他们之间的陈述。

最后的“GO&#39;声明不在文件的末尾 - 在最后一个声明之后有一些“INSERT INTO&#39;线。这在SSMS中执行时工作正常,但在上面的构造中不适用于C#。

我放了一个计数器来计算&#39; commandText&#39;在循环中。我有3107.在我添加了一个&#39; GO&#39;在文件的末尾,我的计数器显示3108仍然得到错误。在这两种情况下,所有数据都完全插入到我的表中,因此错误发生在最后。 任何想法都可能是什么?

2 个答案:

答案 0 :(得分:0)

如果您使用字符串生成器会更容易。您可以使用字符串builder.append类添加新的字符串行

答案 1 :(得分:0)

如果解析器在GO之前说'语法错误',则表示您已将GO发送到服务器。必须是您的拆分器没有正确拆分。可能就像GO之后的空格一样,使其与\r\nGO\r\n完全不匹配。

您可以尝试https://github.com/rusanu/DbUtilSqlCmd