Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. ExecuteQuery and ExecuteReader

ExecuteQuery and ExecuteReader

Scheduled Pinned Locked Moved Database
databasesysadminquestionannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yueru
    wrote on last edited by
    #1

    I don't know why when I use select with ExecuteQuery my result will have repeated the lastes line. And my friend adviced me that I should use ExecuteReader now it's work What's the different ??? here is my code !!

    public void Add()
    {
    if (File.Exists("" + info + ".db"))
    {
    sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=False;Compress=True;");
    sql_con.Open();
    sql_cmd = sql_con.CreateCommand();
    sql_cmd.CommandText = "drop table par ;";
    sql_cmd.ExecuteNonQuery();
    }
    else
    {
    sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=True;Compress=True;");
    sql_con.Open();
    sql_cmd = sql_con.CreateCommand();
    }
    sql_cmd.CommandText = "create table par (Date nvarchar(20), Time nvarchar(10), Linein NVARCHAR(20), Lineout NVARCHAR(20), Number NVARCHAR(20), Status nvarchar(10),Duration int(20), Cost nvarchar(20), Detail nvarchar(10), Network nvarchar(10));";
    sql_cmd.ExecuteNonQuery();
    StreamReader reader = new StreamReader(inputfilename);
    string line = reader.ReadLine();
    while (line != null)
    {
    string NNDuration = line.Replace("'", "''");
    string Date = line.Substring(12, 8);
    if (line[11] == '=')
    {
    string Time = line.Substring(21, 5);
    string Linein = line.Substring(27, 10);
    string Lineout = line.Substring(38, 1);
    if (string.Compare(Lineout, "0") >= 0 && string.Compare(Lineout, "9") <= 0)
    {
    string Number = line.Substring(40, 20);
    string Status = line.Substring(61, 3);
    string NDuration = NNDuration.Substring(65, 10);
    string b = NDuration.Substring(2, 2);
    string c = NDuration.Substring(6, 2);
    int y = Convert.ToInt32(b);
    int l = Convert.ToInt32(c);
    int Duration = y + l;
    string OCost = line.Substring(73, 5);
    string Cost = OCost.Trim();
    string Detail = line.Substring(79, 3);
    string Network = line.Substring(

    S S 2 Replies Last reply
    0
    • Y yueru

      I don't know why when I use select with ExecuteQuery my result will have repeated the lastes line. And my friend adviced me that I should use ExecuteReader now it's work What's the different ??? here is my code !!

      public void Add()
      {
      if (File.Exists("" + info + ".db"))
      {
      sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=False;Compress=True;");
      sql_con.Open();
      sql_cmd = sql_con.CreateCommand();
      sql_cmd.CommandText = "drop table par ;";
      sql_cmd.ExecuteNonQuery();
      }
      else
      {
      sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=True;Compress=True;");
      sql_con.Open();
      sql_cmd = sql_con.CreateCommand();
      }
      sql_cmd.CommandText = "create table par (Date nvarchar(20), Time nvarchar(10), Linein NVARCHAR(20), Lineout NVARCHAR(20), Number NVARCHAR(20), Status nvarchar(10),Duration int(20), Cost nvarchar(20), Detail nvarchar(10), Network nvarchar(10));";
      sql_cmd.ExecuteNonQuery();
      StreamReader reader = new StreamReader(inputfilename);
      string line = reader.ReadLine();
      while (line != null)
      {
      string NNDuration = line.Replace("'", "''");
      string Date = line.Substring(12, 8);
      if (line[11] == '=')
      {
      string Time = line.Substring(21, 5);
      string Linein = line.Substring(27, 10);
      string Lineout = line.Substring(38, 1);
      if (string.Compare(Lineout, "0") >= 0 && string.Compare(Lineout, "9") <= 0)
      {
      string Number = line.Substring(40, 20);
      string Status = line.Substring(61, 3);
      string NDuration = NNDuration.Substring(65, 10);
      string b = NDuration.Substring(2, 2);
      string c = NDuration.Substring(6, 2);
      int y = Convert.ToInt32(b);
      int l = Convert.ToInt32(c);
      int Duration = y + l;
      string OCost = line.Substring(73, 5);
      string Cost = OCost.Trim();
      string Detail = line.Substring(79, 3);
      string Network = line.Substring(

      S Offline
      S Offline
      Satish Pai
      wrote on last edited by
      #2

      Hi, DateReader is an forward only and read only cursor type if you are accessing data through DataRead it shows the data on the web form/control but you can not perform the paging feature on that record(because it's forward only type). Reader is best fit to show the Data (where no need to work on data) DataAdapter is not only connect with the Databse(through Command object) it provide four types of command (InsertCommand, UpdateCommand, DeleteCommand, SelectCommand), It supports to the disconnected Architecture of .NET show we can populate the records to the DataSet. where as Dataadapter is best fit to work on data.

      1 Reply Last reply
      0
      • Y yueru

        I don't know why when I use select with ExecuteQuery my result will have repeated the lastes line. And my friend adviced me that I should use ExecuteReader now it's work What's the different ??? here is my code !!

        public void Add()
        {
        if (File.Exists("" + info + ".db"))
        {
        sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=False;Compress=True;");
        sql_con.Open();
        sql_cmd = sql_con.CreateCommand();
        sql_cmd.CommandText = "drop table par ;";
        sql_cmd.ExecuteNonQuery();
        }
        else
        {
        sql_con = new SQLiteConnection("Data Source= " + info + ".db;Version=3;New=True;Compress=True;");
        sql_con.Open();
        sql_cmd = sql_con.CreateCommand();
        }
        sql_cmd.CommandText = "create table par (Date nvarchar(20), Time nvarchar(10), Linein NVARCHAR(20), Lineout NVARCHAR(20), Number NVARCHAR(20), Status nvarchar(10),Duration int(20), Cost nvarchar(20), Detail nvarchar(10), Network nvarchar(10));";
        sql_cmd.ExecuteNonQuery();
        StreamReader reader = new StreamReader(inputfilename);
        string line = reader.ReadLine();
        while (line != null)
        {
        string NNDuration = line.Replace("'", "''");
        string Date = line.Substring(12, 8);
        if (line[11] == '=')
        {
        string Time = line.Substring(21, 5);
        string Linein = line.Substring(27, 10);
        string Lineout = line.Substring(38, 1);
        if (string.Compare(Lineout, "0") >= 0 && string.Compare(Lineout, "9") <= 0)
        {
        string Number = line.Substring(40, 20);
        string Status = line.Substring(61, 3);
        string NDuration = NNDuration.Substring(65, 10);
        string b = NDuration.Substring(2, 2);
        string c = NDuration.Substring(6, 2);
        int y = Convert.ToInt32(b);
        int l = Convert.ToInt32(c);
        int Duration = y + l;
        string OCost = line.Substring(73, 5);
        string Cost = OCost.Trim();
        string Detail = line.Substring(79, 3);
        string Network = line.Substring(

        S Offline
        S Offline
        saanj
        wrote on last edited by
        #3

        Use ExecuteNonQuery to use DML statements like insert, update, delete etc. Use ExecuteReader to use select statement for fast and forward only data retirveal from the database.

        Either you love IT or leave IT...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups