sqldataadapter

DataGridView, DataTable, SqlDataAdapter and SqlCommandBuilder - disable deletes

I have a WinForm that has a DataGridView table. It is bound to a DataTable in conjunction with a SqlDataAdapter and SqlCommandBuilder. What is the best way (easy and easy to manage) of disabling Deletes but allowing Selects, Updates, Inserts? Is there a one line property I can set on the grid? That is how I would prefer to do it. ...

SqlCommandBuilder and SQL Server Computed Columns - Error

What is the right way to avoid errors on INSERT and UPDATES with a SqlDataAdapter/SqlCommandbuilder when the SQL Statement used to SELECT has a computed column as one of the return fields? I get the error now that "The column Amount cannot be modified because it is either a computed column or is the result of a UNION operator". UPDATE:...

Is there a problem when I call SqlAdapter.Update and at the same time call SqlDataReader.Read

I have two applications, one updates a single table which has constant number of rows (128 rows) using SqlDataAdapter.Update method , and another application that select from this table periodically using SqlDataReader. sometimes the DataReader returns only 127 rows not 128, and the update application does not remove or even insert any ...

ConstraintException on insert into primary key

I had a typed dataset with three tables in master-detail relationships and got the error "Failed to enable constraints. One or more rows contain values ciolating non-null, unique or foreign-key constraints." I couldn't figure out where the issue came from and finally simplified tho whole thing to this: New typed dataset containing one ...

SqlDataAdapter and UpdateBatchSize

I am running into a problem when setting the UpdateBatchSize property to a number > 1 on my data adapter. I only get an error when I have a very specific type of DataRelationship on the table. Consider: Table JobProductColorSize Columns: Id : long //is a primary key ParentAssemblyId : long? Therefore I have a DataRelation created ...

how to determine if zero records are return in SqlDataAdapter

i have the following code string connString = ConfigurationManager.ConnectionStrings["XXXConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlDataAdapter SQLDataAdapter1 = new SqlDataAdapter("SELECT * FROM EVENTSignUp WHERE (MembmerEmail = " + userInfo.Email ...

How bad is opening and closing a SQL connection for several times? What is the exact effect?

For example, I need to fill lots of DataTables with SQLDataAdapter's Fill() method: DataAdapter1.Fill(DataTable1); DataAdapter2.Fill(DataTable2); DataAdapter3.Fill(DataTable3); DataAdapter4.Fill(DataTable4); DataAdapter5.Fill(DataTable5); .... .... Even all the dataadapter objects use the same SQLConnection, each Fill method will open...

SqlDataAdapter Insert with Multiple Tables

I have a static class which loads the initial data for my c# windows forms application. The data is retrieved via 1 sqldataadapter with one query selecting from multiple sql server tables. These are then used to populate multiple datatables like so and filled into my dataset da.TableMappings.Add("Table", "ChannelTypes"); da.TableMapping...

.Net DbDataAdapter has wrong primary key on filled datatable and i want to correct this

Hi all, .NET/MSSQL Server Question: I use a System.Data.SqlClient.SqlDataAdapter to connect to a database and read (.Fill) a datatable from a view in the database (select * from v_coolview). The problem is that the view consists of multiple tables (of course) and the resulting DataTable has typically a primary key set (Datatable.Primar...

How do I set the timeout when filling a temporary table based on a complex query?

How do I set the command timeout in the following situation? Just to clarify, I have already set the connection timeout in the Connection String, but I also need to set the command timeout because I want the query to be able to run 5 minutes if it needs to, but it times out in less than a few minutes. String reportQuery = @" compli...

Building SQL Query with SQL Data Adapter? Generating query off of configuration section

I'm not sure if I'm approaching this the correct way, but am very open and appreciative of any suggestions. I am building a chart off of data in a SQL database. The chart has 'Age' and 'Percentile' or those are the 2 fields I am most concerned with. I have a config section in my web.config called 'Percentiles'. This is so the percenti...

DataSet Takes Only One DataGridView Change When Calling DataAdapter.Update

I am using the CellEndEdit event in DataGridView to detect when a user has finished editing a cell. I want to post the results back to the database. The datagridview is bound to a DataView. I retain the original DataAdapter (SQLDataAdapter) used to fill the dataset and thus display the data to the user. All update and select commands are...

Using SqlDataAdapter in an ASP.NET page

I'm writing an ASP.NET 2.0 page in VS2008. In my Page_Load method I have the following: DataTable table = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(); using (SqlConnection connection = new SqlConnection(conString)) { using (SqlCommand command = new SqlCommand(cmdString, connection)) { adapter.SelectComma...

Get ID of the newly inserted record, using SqlDataAdapter

BGREX.BGREXDataTable _bRexDataTable = new BGREX.BGREXDataTable(); BGREX.BGREXRow bgRexRow = _bRexDataTable.NewBGREXRow(); bgRexRow.BGRes_TITLE = "abc"; bgRexRow.BGRes_VERSION = 123; _bRexDataTable.AddBGREXRow(bgRexRow); int rewEffected = Adapter.Update(_bRexDataTable); Have beed using above to insert record in Database, workes perfec...

SQL - SQLDataAdapter Update causing primary key violation

I need to be able to change the primary keys in a table. The problem is, some of the keys will be changing to existing key values. E.g. record1.ID 3=>4 and record2.ID 4=>5. I need to keep these as primary keys as they are set as foreign keys (which cascade up update) Is there a reasonable way to accomplish this, or am I attempting sql...

lost with DataSets and merging in C#

NEWEST EDIT!!! PLEASE... I have been through many permutations of this code. I am attempting to take some certain related records from a database (SQL server) and export to XML (which seems to work!), and take them to a disconnected copy of that database, and import them to that database, merging them by primary key (updating if the k...

SqlDataAdapter Update

Can any one help me why this error occurs when i update using sqlDataadapter with join query Dynamic SQL generation is not supported against multiple base tables. ...

How can I synchronise two datatables and update the target in the database?

I am trying to synchronise two tables between two databases. I thought that the best way to do this would be to use the DataTable.Merge method. This seems to pick up the changes, but nothing ever gets committed to the database. So far I have: string tableName = "[Table_1]"; string sql = "select * from " + tableName; ...

C# SqlDataAdapter not populating DataSet

I have searched the net and searched the net only to not quite find the probably I am running into. I am currently having an issue getting a SqlDataAdapter to populate a DataSet. I am running Visual Studio 2008 and the query is being sent to a local instance of SqlServer 2008. If I run the query SqlServer, it does return results. Code...

Can the SqlDataAdapter refresh itself when the table is changed from an outside source?

My SQL Server table is updated from outside of my program (from a SQL trigger, actually), so the DataSet doesn't realize that there are changes and my DataGrid doesn't update unless I explicitly call SqlDataAdapter.Fill() again (e.g. with a "Refresh" button or a timed event). Is there a way that ADO.NET can subscribe to change events or...