ado.net

.NET Fastest way to iterate through rows in a datatable?

Which is generally fastest when reading/comparing row info from a DataTable? 'assume dt as datatable' 'method 1' dim i as int32 for i = 0 to dt.rows.count - 1 .... next 'method 2' dim row as datarow for each row in dt.rows .... next And if there's a difference, in what circumstances does it pay to use one over the other? Th...

Add a CheckBox column to a GridView with persistence

I have an ASP.NET application that displays various views into a largish database of protein sequences. As a visitor browses the data, I'd like for them to be able to select a CheckBox in the GridView row to flag sequences for later download as a zipped text file. I don't want to store the selections so they should just be valid for th...

Retrieving the new ID from a SQLDataAdaptor.Update

How would you go about retrieving the @@IDENTITY value for each row when the SQLDataAdapater.Update is executed on a table? eg. Is it possible to modify/intercept the InsertCommand, generated by the SQLCommandBuilder, to say add an output parameter, and then retrieve its value in the da.RowUpdated event??? ...

Are there any classes (or methods) that can create a formatted connection string, given a provider name and user id, password etc?

Eg. ConnectionDetails cd = new ConnectionDetails (); cd.ProviderName = "System.Data.OleDb"; cd.DataSource = "serverAddress"; cd.Catalog = "database"; cd.UserId = "userId"; cd.Password = "password"; string connectionString = cs.CreateConnectionString(); // Should return: // "Provider=SQLOLEDB;Data Source=serverAddress;Initial Catalog=da...

How to determine whether SqlConnection is enlisted into a System.Transactions' tx or not?

Hello. When we using a transation from System.Transactions (creating TransationScope for an instance) by default all Sql-connections (System.Data.SqlClient.SqlConnection) (but is't also the true for Oracle.DataAccess.OracleConnection) are enlisted on opening. That's called auto-enlistment. Nice feature. But it can be turned off throught ...

Persistence framework?

I'm trying to decide on the best strategy for accessing the database. I understand that this is a generic question and there's no a single good answer, but I will provide some guidelines on what I'm looking for. The last year we have been using our own persistence framework, that although limited has server as well. However it needs some...

Can you use ADO.NET SQLCommandBuilder with composite keys?

I have a database table with 6 columns. The primary key is a composite key made up of 5 of the 6 columns I am trying to use the SqlClient.SqlCommandBuilder.GetDeleteCommand to delete the row. However I am getting the following error: "System.InvalidOperationException : Dynamic SQL generation for the DeleteCommand is not supported again...

C# ADO.NET: nulls and DbNull -- is there more efficient syntax?

I've got a DateTime? that I'm trying to insert into a field using a DbParameter. I'm creating the parameter like so: DbParameter datePrm = updateStmt.CreateParameter(); datePrm.ParameterName = "@change_date"; And then I want to put the value of the DateTime? into the dataPrm.Value while accounting for nulls. I thought initially I'd b...

how to close connection/datareader when using SqlDataSource or ObjectDataSource

Hi, during beta testing we discovered connection pooling error messages . Therefore I have been going through the code and closing down the SqlDataReader objects wherever they have been left unclosed. What I need to know is how to close a datareader (or if there is a need at all to close) that is specified in the SelectStatement attribu...

Database Localization - Lookup lists - smarter way

I'm looking to add some lookup lists in the database, but I want them to be easy localizable (SQL 2005, ADO.NET) This would include: Easy Management of multiple languages at the same time Easy Retrieval of values from the database Fallback language (in case the selected language is missing) I was thinking about having a table that w...

Receive parameter from request body in WCF/ADO.NET Data Service

I'm tryint to post to a ADO.NET Data Service but the parameters seems to get lost along the way. I got something like: [WebInvoke(Method="POST")] public int MyMethod(int foo, string bar) {...} and I make an ajax-call using prototype.js as: var args = {foo: 4, bar: "'test'"}; new Ajax.Requst(baseurl + 'MyMethod', method: 'POST', ...

ADO.NET Data Services Query Interceptor - can anyone tell me the VB syntax of this C#?

Hi folks, I am pretty new to VB.NET - and I'm struggling to convert the signature of the method in the following code snippet. The Expression<...>> bit. Thanks in advance. [QueryInterceptor("Orders")] public Expression<Func<Orders,bool>> OnQueryOrders() { return o => o.Customer.ContactName == HttpContext.Current.User...

Why is OdbcCommand.ExecuteScalar() throwing an AccessViolationException?

I have a block of code intended to pull text descriptions from a database table and save them to a text file. It looks like this (C# .NET): OdbcCommand getItemsCommand = new OdbcCommand("SELECT ID FROM ITEMS", databaseConnection); OdbcDataReader getItemsReader = getItemsCommand.ExecuteReader(); OdbcCommand getDes...

Avoiding SQL Injection in SQL query with Like Operator using parameters?

Taking over some code from my predecessor and I found a query that uses the Like operator: SELECT * FROM suppliers WHERE supplier_name like '%'+name+%'; Trying to avoid SQL Injection problem and parameterize this but I am not quite sure how this would be accomplished. Any suggestions ? note, I need a solution for classic ADO.NET - I d...

How do I transfer data from one database to another using a DataSet?

As usual, some background information first: Database A (Access database) - Holds a table that has information I need from only two columns. The information from these two columns is needed for an application that will be used by people that cannot access database A. Database B (Access database) - Holds a table that contains only two c...

rhino-mocks - good sample apps

Hi guys I know that there has been a couple questions about tutorials on rhino-mocks. But I am wondering if there are any sample apps out there that use rhino-mocks in the context of an n-tier business application using ado.net. I find the tutes good, but they don't seem to bring everything all together into the big picture. Thus, I ...

Quickest way to setup this asp.net page against MS Access DB . . .

I have an access database with 3 tables. People Gifts PeopleGifts Using VS 2008, what is the quickest way to get a page up and running which allows me to run queries against these tables and do basic inserts. I want to have comboboxs bound to fields in the table so a user can click on a person and click on a gift and they click "A...

How to get only the schema of the database into a dataset?

How to load only the schema of the tables into a dataset. ...

Cross-referencing across multiple databases

I have two databases, one is an MS Access file, the other is a SQL Server database. I need to create a SELECT command that filters data from the SQL Server database based on the data in the Access database. What is the best way to accomplish this with ADO.NET? Can I pull the required data from each database into two new tables. Put thes...

moq - good sample apps

Hi guys I know that there has been a couple questions about tutorials on moq. But I am wondering if there are any sample apps out there that use moq in the context of an n-tier business application using ado.net. I find the tutes good, but they don't seem to bring everything all together into the big picture. Thus, I am looking for a s...