TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Srinivas M
NA
435
29.4k
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();
// }
//}
}
}
Reply
Answers (
2
)
0
Srinivas M
0
435
29.5k
Apr 18 2016 10:00 AM
Hi vincent already i have seen that documentation but their implementing normal Datareader and DataAdapter methods are implemented but i want ot implement Pure IDataReader and IDataAdapter methods implementation because we are using these Interface Implementation methods in Client appplication,just we call these methods and pass query and parameters.
0
Vincent Maverick Durano
119
14.9k
4.2m
Apr 12 2016 8:10 AM
have you tried looking into the official documentation of IDataReader interface: https://msdn.microsoft.com/en-us/library/system.data.idatareader(v=vs.110).aspx
how to change enter page lanuguage like google
send hl7 using vb.net with mllp