Srinivas M

Srinivas M

  • 1.3k
  • 435
  • 29k

How to implement Idatareader and idataAdaptor methods ?

Apr 11 2016 7:34 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using System.Data.SqlClient;
namespace CF.OpenAPI.DBFacade
{
public class MSSqlDatabase : IDatabase
{
private Database _database;
public Database ConcreteDatabase
{
get { return _database; }
set { _database = value; }
}
/// <summary>
/// Configuration key that defines the database connection string.
/// </summary>
/// <param name="key"></param>
public MSSqlDatabase(String key)
{
this.ConcreteDatabase = DatabaseFactory.CreateDatabase(key);
}
public System.Data.IDataReader DoReaderQuery(string query, Dictionary<string, string> paramcoll)
{
string sql = query;
IDbConnection Connection;
//IDbCommand cmd = Connection.CreateCommand();
IDbCommand cmd = Connection.CreateCommand();
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
IDbDataParameter p = cmd.CreateParameter();
p.ParameterName = "";
p.DbType = DbType.String;
p.Value = paramcoll;
cmd.Parameters.Add(p);
IDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1]));
}
reader.Close();
return reader;
// throw new NotImplementedException();
}
public System.Data.IDataAdapter DoAdapterQuery(string query)
{
using (IDbConnection connection = new SqlConnection(query))
{
connection.OpenAsync();
IDbCommand command = connection.CreateCommand();
command.CommandText = query;
using (IDataReader reader = command.ExecuteReaderAsync()
{
do
{
while (reader.ReadAsync())
{
if (!reader.IsDBNullAsync(0))
{
var name = reader.GetFieldValueAsync<string>(0);
Assert.IsNotNull(name);
}
}
} while (reader.NextResultAsync());
}
throw new NotImplementedException();
}
public int DoNonExecuteQuery(string query)
{
int i=cmd.ExecuteNonQuery();
throw new NotImplementedException();
}
public void BeginTransaction()
{
throw new NotImplementedException();
}
public void EndTransaction()
{
throw new NotImplementedException();
}
public void RollBackTransaction()
{
throw new NotImplementedException();
}
public void IsInTransaction()
{
throw new NotImplementedException();
}
//public void DoReaderQuery(string query, Dictionary<string, string> paramcoll)
//{
// string queryString = query;
// using (SqlConnection connection = new SqlConnection(query))
// {
// SqlCommand command = new SqlCommand(queryString, connection);
// connection.Open();
// SqlDataReader reader = command.ExecuteReader();
// // Call Read before accessing data.
// while (reader.Read())
// {
// Console.WriteLine(String.Format("{0}, {1}",
// reader[0], reader[1]));
// }
// // Call Close when done reading.
// reader.Close();
// }
//}
}
}

Answers (2)