ExecuteQuery and ExecuteReader
-
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( -
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(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.
-
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(