ado.net

Custom .NET Data Providers

梦想与她 提交于 2020-01-01 02:49:04
问题 Is is possible to use a custom .NET data provider without installing it in the GAC? Can I reference a custom DLL and register it inside my configuration file? 回答1: Yes , you can register an implementation of the DbProviderFactory class by adding the following section in your configuration file: <system.data> <DbProviderFactories> <add name="My Custom Data Provider" invariant="MyCustomDataProvider" description="Data Provider for My Custom Store" type="MyNamespace.MyCustomProviderFactory,

Entity Framework - redundant connection string

匆匆过客 提交于 2020-01-01 02:40:14
问题 I'm using Entity Framework 4 in my project. The Framework has created its own connection string, so my web.config connectionStrings section file looks following: <connectionStrings> <add name="ApplicationServices" connectionString="data source=localhost;user id=user;pwd=pass;initial catalog=VNK" providerName="System.Data.SqlClient" /> <add name="VNKEntities" connectionString="metadata=res://*/VNKModel.csdl|res://*/VNKModel.ssdl|res://*/VNKModel.msl;provider=System.Data.SqlClient;provider

Getting datarow values into a string?

大城市里の小女人 提交于 2020-01-01 01:12:11
问题 I have a dataset called "results" with several rows of data. I'd like to get this data into a string, but I can't quite figure out how to do it. I'm using the below code: string output = ""; foreach (DataRow rows in results.Tables[0].Rows) { output = output + rows.ToString() + "\n"; } However, I think I'm missing something because this isn't working. Can someone point me in the right direction? 回答1: You need to specify which column of the datarow you want to pull data from. Try the following:

Passing list of objects to a SQL Server stored procedure and insert records using asp.net core

微笑、不失礼 提交于 2020-01-01 00:53:09
问题 I am working on asp.net application. I am using ado.net to access the SQL Server database and perform CRUD. I want to insert multiple records in one go. For this purpose, I have added a custom Type in database and a stored procedure like this: CREATE TYPE [dbo].[UserTableType] AS TABLE ( [FirstName] [nvarchar](100) NULL, [LastName] [nvarchar](100) NULL, [UserName] [nvarchar](100) NULL, [Password] [nvarchar](100) NULL, [IsActive] [bit] NULL, [IsDeleted] [bit] NULL, [CreatedBy] [int] NULL,

IDisposable on an injected repository

大城市里の小女人 提交于 2019-12-31 16:40:17
问题 I have the following ADO .Net Repository public class Repository : IRepository, IDisposable { private readonly IUnitOfWork UnitOfWork; private SqlConnection Connection; public Repository(IUnitOfWork unitOfWork, connectionString) { UnitOfWork = unitOfWork; Connection = new SqlConnection(connectionString); Connection.Open(); } public MyObject FindBy(string userName) { //...Ado .Net command.ExecuteReader, etc. } } This repository is injected with an IoC container to a Domain Service and is used

Best way to copy Data from one DataTable to another DataTable with diffrent structure

时光怂恿深爱的人放手 提交于 2019-12-31 06:56:08
问题 I am copying data from DataTable to another DataTable with a structure. I have to hardcode columns number in the loop and copy the data in object array. What will be the best way to achieve it ? IEnumerable<DataRow> query = from vendInv in VendorInvoiceStagingTable.AsEnumerable() where vendInv.Field<string>(VendInvoice.Number) == InvoiceHeader select vendInv; Object[] obj = new Object[10]; var item = query.First(); for (int idx = 0; idx < 10; idx++) { obj[idx] = item[idx]; }

Insert, select and update DateTime

▼魔方 西西 提交于 2019-12-31 03:34:06
问题 I have a table with time the column named time and the datatype is Date . In asp.net I want a query to insert the date, and another so select between 2 date. I already try this: string data = DateTime.Now.ToShortDateString(); //date= 28/10/2014 -> dd/mm/yyyy string comando = "INSERT INTO example (date) values '" +data+ "+"'"; And I used that query to select between 2 dates select * from example where date >= '25/10/2014' and date <= '28/10/2014' I already tried with datatype varchar but it

NHibernate and database connection failover?

天涯浪子 提交于 2019-12-31 02:19:15
问题 I am using NHibernate to connect to a legacy rdbms system. Under high production load the rdbms service fails. To maintain the availability we have a failover rdbms service. Is there a way to configure NHibernate to use the FailOver Connection String when the primary connection is down? Additional Info: I am using Castle over NHibernate. If Castle provides handling of failover connections then that will also do it for me. 回答1: You can build your own NHibernate.Connection.IConnectionProvider

How to get original DataColumn value from DataRow?

ぃ、小莉子 提交于 2019-12-31 01:56:11
问题 I have a DataTable and i want to figure out the Original column value for all the modified data rows. I am using following approach to get the Orginal column value before the DataRow was modified DataRow[] dataRowArray = dataTableInstance.Select(null,null,DataViewRowState.OriginalRows); DataRow originalDataRow = dataRowArray[rowIndex][columnIndex, DataRowVersion.Original] Please point out what am I doing wrong here ? Above code does not give me the Original column , instead it gives me the

The type or namespace name 'oracle' could not be found error

大城市里の小女人 提交于 2019-12-31 00:59:06
问题 I am building C# Console Application to connect with database and do simple query. But when I debug program, I get this error: The type or namespace name 'Oracle' could not be found ( are you missing a using directive or an assembly reference? ) I need to use: using Oracle.DataAccess.Client; I have downloaded from Oracle site ODAC pack. Inside I have Install batch file ( i have used it ) but nothing still. I am using MS VS2012 Express for Windows Desktop. What file should I include when