日期:2014-05-18  浏览次数:20686 次

数据库数据全体自加一的问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Data;  
using System.Data.Common;  
using System.Data.SQLite;

namespace test
{
  class Program
  {
  static void Main(string[] args)
  {
  System.Data.SQLite.SQLiteConnection.CreateFile("datasource");

  System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();

  string datasource = "D:/Data.db";
 
  System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();

  connstr.DataSource = datasource;

  conn.ConnectionString = connstr.ToString();

  conn.Open();

  System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();

  cmd.Connection = conn;

  Stopwatch watch = new Stopwatch();

  watch.Start();
   
  string sql= "SELECT * FROM test ";

  cmd.CommandText = sql;

  cmd.ExecuteNonQuery();

  System.Data.SQLite.SQLiteDataReader reader = cmd.ExecuteReader();

  watch.Stop();

  Console.WriteLine(watch.Elapsed);

  Console.ReadLine();
  }
  }
}
   
select from怎样遍历所有数据后自加一
   
   




   
   
 

------解决方案--------------------
应该用这条sql语句
update 表名 set 年龄=年龄+1

直接cmd.ExecuteNonQuery();就可以把数据表中所有记录的“年龄”字段加上1