ado.net

Can DataSet handle self-referential relationship?

Hi, I have the following tables: Data ID ... Relationships ParentID //points to Data:ID ChildID //points to Data:ID too If I bring both the DATA and RELATIONSHIPS table into a dataset, is there a way to add the relationships into the model in a way that would add value? e.g. to enforce the constraints for example? If so I ...

How do you change specific data in a datatable column?

I've populated a DataTable with a DataAdapter but I would like to change the values dynamically for all of the rows in that column in the DataTable. How do I go about doing this? Here is my current code: SqlConnection conn = null; string sSQL = ""; string connString = "Datasourceetc"; sSQL = "SELECT TEST_ID FROM TEST_TABLE"; SqlData...

Ado.net entity data model doesn't exist

I've intalled vs2008 ts on my windows 7 x64 pc, but when I tried to add ado.net entity data model there is no template for it. All the MSDN tutorials say that vs2008 has it. ...

Atomicity of Data Adapter in ADO.NET

Hi, I am new to ADO.NET and learning it. I was wondering if Data Adapter in ADO.NET provides atomicity or ACID properties by itself when filling the Data Set and updating the Database or do we have to use transaction explicitly to achieve this. Lets say, I want to fetch data from the Database through the Data Adapter to a Data Set Se...

How to create a proper database layer?

Currently I use a lot of the ado.net classes (SqlConnection, SqlCommand, SqlDataAdapter etc..) to make calls to our sql server. Is that a bad idea? I mean it works. However I see many articles that use an ORM, nHibernate, subsonic etc.. to connect to SQL. Why are those better? I am just trying to understand why I would need to change thi...

Are .NET automatic data forms a good idea?

I'm a Linux guy usually, but at the moment I'm trying to evaluate .NET for a Windows desktop application. All it needs to do is to display some forms that link to a database, let the user edit the data and then produce reports based on it. I found a walkthough at http://msdn.microsoft.com/en-us/library/ms171884.aspx that automatically pr...

Is there a standard dialog for constructing an ADO.Net connection string (that is redistributable)?

I want to use a standard dialog to solicit user input of an ADO.net connection string. It is trivial to do for the oledb connection string as described here: MSDN Article on MSDASC.DataLinks().Prompt I've also found examples that use Microsoft.Data.ConnectionUI.dll and MicrosoftData.ConnectionUI.Dialog.dll from VS (HOWTO: Using the Cho...

List<T> fill collection performance

Hi, all I am having performance problem when truing to fill typed list. Below is my simplified code: public static List<Product> GetProducts() { List<Product> products = new List<Product>(); using (DbQuery query = new DbQuery()) //this is database access class { query...

Need recordset behavior in VB.NET w/ADO help

Hello all. VB.NET newbie here. I've learned (through this site) how to negotiate a dataset via: For Each dRow In quanDS.Tables(0).Rows 'do something to each row Next I now need to figure out now to loop through a subset of the records returned in the dataset - here's a VB6 example I need to convert: strSQL = "select * from tblDQ ...

Convert DataColumn.DataType to SqlDbType

Is there a converter for going from DataColumn.DataType to SqlDbType? Or do I have to write a method to do it? Edit: Found a couple of options at Dot Net Pulse and CodeProject. I eventually went with the CodeProject code converted from VB.NET to C#: private SqlDbType GetDBType(System.Type theType) { SqlClient.SqlParameter p1; ...

Entity Framework ObjectContext -> raw SQL calls to native DBMS

I have an app using the ADO.NET entity framework (the VS2008 version, not the newer, cooler one) and I need to be able to make a call down to the underlying DBMS (it's postgres) in order to call some SQL that Entity Framework doesn't support. Is there a way to go from an Entity Framework ObjectContext to something that will let me exec...

Does ADO.NET Entity Framework have a construct similar to Linq-To-SQL's GetTable<T>

I'm trying to do something similar in Entity Framework, that I'm very used to doing in Linq-To-Sql. Now my question is if EF has the same capability, that I'm unable to figure out. Linq-To-Sql: dataContext.GetTable<T>(); Would yield a Queryable collection of type 'T'. In Entity Framework I would like to do the same: //NOTICE: T...

what to check for when a datareader might not have a particular column?

I am doing a null check but I am getting a index of out range exception when doing: if(myReader["column1"] != null) { } Under certain conditions that column will not be present, why isn't a null check working? ...

ADO.NET (Sql Compact + MySQL + IBM db2 expressC)

I'm developing an app which will have a central database users can add entries to. The database will have to be on a server somewhere but I want the users to be able to add entries offline. The app will sync to the main db when connection is available. So, I supose I need 2 databases - the main one sitting on a server (preferably linux) ...

How do I retrieve DataColumn.DefaultValue from a Sql Table?

Is there a way to determine a column's defaultvalue from the Sql Database using ado.net? I tried using the SqlDataAdapter's FillSchema method: using (SqlDataAdapter adapter = new SqlDataAdapter()) { adapter.SelectCommand = myConnection.CreateCommand(); adapter.SelectCommand.CommandType = CommandType.Text; adapter.SelectCom...

How to get schema of our table without filling its DataTable before calling NewRow method?

Hi all. I know that I should have schema of a table before calling NewRow method in order to add a new row to a DataTable.... But as you know, having the schema of a table means filling its DataTable by records from DB. This means connecting to DB and fetch records. Is there any way to have schema without performing a select statement?...

DataTable.AsEnumerable().Distinct() doesn't work because of primary key column

I want to remove duplicates from my DataTable so I'm using DataTable.AsEnumerable().Distinct(DataRowComparer.Default) but it doesn't do what I need. I think because each duplicate row has it's unique primary key column. How can I do what I need? Write my own DataRowComparer? I don't want - because the default must works. ...

Coding approach/pattern to use DataSet as domain objects for a small application?

Hi, Assumption - For a simple app I have with only a few tables & I plan to stay simple and use DataSet for my data access as well as domain layer. In other way, in this small application, I won't create separate classes but rather just use the DataSet directly. Question - Does anyone have any code/patterns/suggestions re how best to...

SQL Server communication protocol issue

Hello everyone, I am using VSTS 2008 + C# + ADO.Net + SQL Server 2008. My questions about what kinds of communication protocols SQL Server 2008 will be using, more details of my questions, If the connection string looks like this, whether Named Pipe or TCP/IP is used? Will different communication protocol being used dependent on wheth...

Disposing the Sql Connection

Just wondering, Would the SqlConnection be diposed/closed when this method is done? Or do i have to explicitly call the close method at the end? using (SqlCommand cmd = new SqlCommand(sql, GetConnection())) { SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { } } SqlConnection GetC...