无法在VS 2012 SqlExpress中插入> 1000条记录

时间:2012-10-31 23:11:07

标签: c# visual-studio visual-studio-2012 sql-server-express

嗯嗯..我有一个本地数据库..使用VS 2012创建..而不是LocalDB ..它的SqlExpress x64 ..

我有一个C#程序,它读取并解析txt文件..并将数据转换为记录..在一个执行流中插入大约200,000条记录..程序解析并创建一个插入查询并执行它。

我使用过Sql对象.. SqlCommand .. SqlConnection .....用于插入..

问题是控制台C#应用程序确实显示所有记录都成功插入到最后一次计数..

但我在DB Table中只能看到1000条记录..

要插入的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace SentiWordDBPopulate
{
class DBPopulateSentiWord
{
    static SqlCommand sqlCmd;
    static SqlConnection sqlConn;

    static void Main(string[] args)
    {
        try
        {
            sqlConn = new SqlConnection("server=localhost\\SqlExpress; DataBase=WordDBForBlogMiner; integrated security=true");
            sqlConn.Open();
            //sqlCmd = new SqlCommand("select * from KWTable", sqlConn);

            //skip 1st 13 lines
            //for (int i = 1; i <= 13; i++)
            //fin.ReadLine();

            string[] lines = File.ReadAllLines("C:\\Users\\Ritesh\\Desktop\\WordDB.txt");

            Console.WriteLine("Done reading! Press enter to insert everything into DB.");
            Console.Read();

            long IDCounter = 0;
            //enter next 117658 lines into DB
            for (int i = 13; i < lines.Length; i++)
            {
                //string line =fin.ReadLine();
                string[] s = (lines[i].Remove(lines[i].IndexOf('#')).Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries));
                //s[5] = s[6] = null;
                s[2] = s[2].Equals("NaN") ? "0" : s[2];
                s[3] = s[3].Equals("NaN") ? "0" : s[3];
                float tempNegScore = float.Parse(s[3]), tempPosScore = float.Parse(s[2]);
                int negScore = (int)Math.Round((tempNegScore * 27), MidpointRounding.AwayFromZero);
                int posScore = (int)Math.Round((tempPosScore * 31), MidpointRounding.AwayFromZero);

                if (posScore <= 31 && negScore <= 27)
                {
                    //Console.WriteLine((++IDCounter) + "\t => " + s[0] + "\t" + posScore + "\t" + negScore + "\t" + s[4]);
                    string category = "";
                    if (posScore.Equals(0) && negScore.Equals(0))
                        category = "neutral";
                    else if (posScore > 0 && negScore.Equals(0))
                        category = "positive";
                    else if (posScore.Equals(0) && negScore > 0)
                        category = "negative";
                    else if (posScore > 0 && negScore > 0)
                        category = "PosNeg";

                    string query = "insert into SentiWordKWTable values ('" + s[0] + "', " + (++IDCounter) + ", " + posScore + ", " + negScore + ", '" + s[4].Replace("'", "") + "', '" + category + "')";
                    sqlCmd = new SqlCommand(query, sqlConn);
                    sqlCmd.ExecuteNonQuery();
                    Console.WriteLine("Record Num: " + IDCounter + " successfully inserted!");
                }
                else
                {
                    Console.WriteLine((++IDCounter) + "\t => " + s[0] + "\t" + posScore + "\t" + negScore + "\t" + s[4]);
                    break;
                }

                tempNegScore = tempPosScore = 0;
                posScore = negScore = 0;
            }
            Console.Read();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception occured => " + e.Message);
            sqlCmd = new SqlCommand("delete from SentiWordKWTable", sqlConn);
            sqlCmd.ExecuteNonQuery();
            Console.WriteLine("all rows of table deleted");
        }
        Console.Read();
    }
}

}

这在VS 2008早期不是问题..在VS 2012中是否有一些限制..或者为&gt; 1000插入启用了什么? ..

1 个答案:

答案 0 :(得分:0)

这只是可见性选项。顶部有一个小工具栏,其中包含一个字段:Max Rows:1000 我选择了“全部”,一切都可见...... * facepalm *

很抱歉给大家带来麻烦,谢谢@MarcGravell我会使用参数而不是连接。