am binding my DataGrid using a StoredProc which uses an OuterJoin query as
follows:
CREATE PROCEDURE spGetClientExpenses
@Client_ID int
AS
SELECT Expense_Details.Exp_Detail_ID,Expense_Details.Exp_ Cat_ID,
CASE WHEN Client_Expenses.Client_ID IS NULL THEN @Client_ID ELSE
Client_Expenses.Client_ID END AS Client_ID,Expense_Details.Description,
CASE WHEN Client_Expenses.CashExpenditure IS NULL THEN 0 ELSE
Client_Expenses.CashExpenditure END AS CashExpenditure,
CASE WHEN Client_Expenses.CreditExpenditure IS NULL THEN 0 ELSE
Client_Expenses.CreditExpenditure END AS CreditExpenditure,
CASE WHEN Client_Expenses.Frequency IS NULL THEN 12 ELSE
Client_Expenses.Frequency END AS Frequency
FROM Expense_Details
LEFT OUTER JOIN Client_Expenses
ON Expense_Details.Exp_Detail_ID = Client_Expenses.Exp_Detail_ID
AND Client_ID = @Client_ID
ORDER BY Description
GO
now when i try and use DataAdapter.Update method after user has made changes
to the DataGrid i get Concurrency exception. Does this mean i can't use
Update method with OuterJoin queries? Please help 4 2640
A concurrency exception will occur when no rows are affected by the SQL
statement.
Sijin Joseph http://www.indiangeek.net http://weblogs.asp.net/sjoseph
Job Lot wrote: am binding my DataGrid using a StoredProc which uses an OuterJoin query as follows:
CREATE PROCEDURE spGetClientExpenses @Client_ID int AS SELECT Expense_Details.Exp_Detail_ID,Expense_Details.Exp_ Cat_ID, CASE WHEN Client_Expenses.Client_ID IS NULL THEN @Client_ID ELSE Client_Expenses.Client_ID END AS Client_ID,Expense_Details.Description, CASE WHEN Client_Expenses.CashExpenditure IS NULL THEN 0 ELSE Client_Expenses.CashExpenditure END AS CashExpenditure, CASE WHEN Client_Expenses.CreditExpenditure IS NULL THEN 0 ELSE Client_Expenses.CreditExpenditure END AS CreditExpenditure, CASE WHEN Client_Expenses.Frequency IS NULL THEN 12 ELSE Client_Expenses.Frequency END AS Frequency FROM Expense_Details LEFT OUTER JOIN Client_Expenses ON Expense_Details.Exp_Detail_ID = Client_Expenses.Exp_Detail_ID AND Client_ID = @Client_ID ORDER BY Description GO
now when i try and use DataAdapter.Update method after user has made changes to the DataGrid i get Concurrency exception. Does this mean i can't use Update method with OuterJoin queries? Please help
Hi Job,
Do you have an UpdateCommand command actually defined in your adapter?
You should provide a valid one if there is none or the existing one is not
good.
(the same goes for Insert and Delete if you need them)
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com www.rthand.com
"Job Lot" <Jo****@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com... am binding my DataGrid using a StoredProc which uses an OuterJoin query as follows:
CREATE PROCEDURE spGetClientExpenses @Client_ID int AS SELECT Expense_Details.Exp_Detail_ID,Expense_Details.Exp_ Cat_ID, CASE WHEN Client_Expenses.Client_ID IS NULL THEN @Client_ID ELSE Client_Expenses.Client_ID END AS Client_ID,Expense_Details.Description, CASE WHEN Client_Expenses.CashExpenditure IS NULL THEN 0 ELSE Client_Expenses.CashExpenditure END AS CashExpenditure, CASE WHEN Client_Expenses.CreditExpenditure IS NULL THEN 0 ELSE Client_Expenses.CreditExpenditure END AS CreditExpenditure, CASE WHEN Client_Expenses.Frequency IS NULL THEN 12 ELSE Client_Expenses.Frequency END AS Frequency FROM Expense_Details LEFT OUTER JOIN Client_Expenses ON Expense_Details.Exp_Detail_ID = Client_Expenses.Exp_Detail_ID AND Client_ID = @Client_ID ORDER BY Description GO
now when i try and use DataAdapter.Update method after user has made changes to the DataGrid i get Concurrency exception. Does this mean i can't use Update method with OuterJoin queries? Please help
Hi Miha
Ya i do have an Update Command defined in the adapter. Below are select,
insert and update command.
da.SelectCommand = New SqlCommand
With da.SelectCommand
.Connection = conn
.CommandType = CommandType.StoredProcedure
.CommandText = "spGetClientExpenses"
.Parameters.Clear()
.Parameters.Add("@Client_ID", 1001)
End With
'Set Insert Command for expenseDA.
da.InsertCommand = New SqlCommand
With da.InsertCommand
.Connection = conn
.CommandType = CommandType.StoredProcedure
.CommandText = "spInsertClientExpenses"
.Parameters.Clear()
.Parameters.Add("@Client_ID", SqlDbType.Int, 4, "Client_ID")
.Parameters.Add("@Exp_Detail_ID", SqlDbType.Int, 4,
"Exp_Detail_ID")
.Parameters.Add("@CashExpenditure", SqlDbType.Money, 8,
"CashExpenditure")
.Parameters.Add("@CreditExpenditure", SqlDbType.Money, 8,
"CreditExpenditure")
.Parameters.Add("@Frequency", SqlDbType.Int, 4, "Frequency")
End With
'Set Update Command for expenseDA.
da.UpdateCommand = New SqlCommand
With da.UpdateCommand
.Connection = conn
.CommandType = CommandType.StoredProcedure
.CommandText = "spUpdateClientExpenses"
.Parameters.Clear()
.Parameters.Add("@Client_ID", SqlDbType.Int, 4, "Client_ID")
.Parameters.Add("@Exp_Detail_ID", SqlDbType.Int, 4,
"Exp_Detail_ID")
.Parameters.Add("@CashExpenditure", SqlDbType.Money, 8,
"CashExpenditure")
.Parameters.Add("@CreditExpenditure", SqlDbType.Money, 8,
"CreditExpenditure")
.Parameters.Add("@Frequency", SqlDbType.Int, 4, "Frequency")
End With
The error I am getting is “Concurrency Violation: the UpdateCommand affected
0 records.”
I can’t figure out why the Adapter.Update method is issuing UpdateCommand,
although there are no records in Client_Expenses table. Below are my insert
and update stored proc. I want to insert and update Client_Expenses table,
whereas the Select command is using outer join. Is there something to with
the outer join?
CREATE PROCEDURE spInsertClientExpenses
@Client_ID int,
@Exp_Detail_ID int,
@CashExpenditure money,
@CreditExpenditure money,
@Frequency int
AS
INSERT Client_Expenses
VALUES
(@Client_ID,@Exp_Detail_ID,@CashExpenditure,@Credi tExpenditure,@Frequency)
GO
CREATE PROCEDURE spUpdateClientExpenses
--Parameters for Client_Expenses Table.
@Client_ID int,
@Exp_Detail_ID int,
@CashExpenditure money,
@CreditExpenditure money,
@Frequency int
AS
--UPDATE Client_Expenses.
UPDATE Client_Expenses
SET CashExpenditure = @CashExpenditure,
CreditExpenditure = @CreditExpenditure,
Frequency = @Frequency
WHERE Client_ID = @Client_ID
AND Exp_Detail_ID = @Exp_Detail_ID
Hi Job,
At first glance it seems ok.
However, from the select of yours I see the following:
SELECT Expense_Details.Exp_Detail_ID,Expense_Details.Exp_ Cat_ID,
CASE WHEN Client_Expenses.Client_ID IS NULL THEN @Client_ID ELSE
Client_Expenses.Client_ID END AS Client_ID,
This practically inserts a "fake" client_id when client_id is actually null.
And your update might use this "fake" id to update and because the id
doesn't exist it doesn't update any row.
Thus it might fail.
Can this be the case?
BTW, it doesn't matter the structure of the select statament (joins, etc.)
as long as it returns correct data.
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com www.rthand.com
"Job Lot" <Jo****@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com... Hi Miha
Ya i do have an Update Command defined in the adapter. Below are select, insert and update command.
da.SelectCommand = New SqlCommand With da.SelectCommand .Connection = conn .CommandType = CommandType.StoredProcedure .CommandText = "spGetClientExpenses" .Parameters.Clear() .Parameters.Add("@Client_ID", 1001) End With
'Set Insert Command for expenseDA. da.InsertCommand = New SqlCommand With da.InsertCommand .Connection = conn .CommandType = CommandType.StoredProcedure .CommandText = "spInsertClientExpenses" .Parameters.Clear() .Parameters.Add("@Client_ID", SqlDbType.Int, 4, "Client_ID") .Parameters.Add("@Exp_Detail_ID", SqlDbType.Int, 4, "Exp_Detail_ID") .Parameters.Add("@CashExpenditure", SqlDbType.Money, 8, "CashExpenditure") .Parameters.Add("@CreditExpenditure", SqlDbType.Money, 8, "CreditExpenditure") .Parameters.Add("@Frequency", SqlDbType.Int, 4, "Frequency") End With
'Set Update Command for expenseDA. da.UpdateCommand = New SqlCommand With da.UpdateCommand .Connection = conn .CommandType = CommandType.StoredProcedure .CommandText = "spUpdateClientExpenses" .Parameters.Clear() .Parameters.Add("@Client_ID", SqlDbType.Int, 4, "Client_ID") .Parameters.Add("@Exp_Detail_ID", SqlDbType.Int, 4, "Exp_Detail_ID") .Parameters.Add("@CashExpenditure", SqlDbType.Money, 8, "CashExpenditure") .Parameters.Add("@CreditExpenditure", SqlDbType.Money, 8, "CreditExpenditure") .Parameters.Add("@Frequency", SqlDbType.Int, 4, "Frequency") End With
The error I am getting is "Concurrency Violation: the UpdateCommand affected 0 records."
I can't figure out why the Adapter.Update method is issuing UpdateCommand, although there are no records in Client_Expenses table. Below are my insert and update stored proc. I want to insert and update Client_Expenses table, whereas the Select command is using outer join. Is there something to with the outer join?
CREATE PROCEDURE spInsertClientExpenses @Client_ID int, @Exp_Detail_ID int, @CashExpenditure money, @CreditExpenditure money, @Frequency int AS INSERT Client_Expenses VALUES (@Client_ID,@Exp_Detail_ID,@CashExpenditure,@Credi tExpenditure,@Frequency) GO
CREATE PROCEDURE spUpdateClientExpenses --Parameters for Client_Expenses Table. @Client_ID int, @Exp_Detail_ID int, @CashExpenditure money, @CreditExpenditure money, @Frequency int AS --UPDATE Client_Expenses. UPDATE Client_Expenses SET CashExpenditure = @CashExpenditure, CreditExpenditure = @CreditExpenditure, Frequency = @Frequency WHERE Client_ID = @Client_ID AND Exp_Detail_ID = @Exp_Detail_ID
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dotnetified |
last post by:
Reposting after about 2 weeks of no response ... thanks if you can help...
----------------------------------------------------------------------------
--------------
To anyone who thinks they...
|
by: Job Lot |
last post by:
am binding my DataGrid using a StoredProc which uses an OuterJoin query as
follows:
CREATE PROCEDURE spGetClientExpenses
@Client_ID int
AS
SELECT...
|
by: hch |
last post by:
dataAdapter.Update(data, "TableName") won’t work!
I was about to deploy my first website on the Internet only to discover that
the dataAdapter.Update() throws the Server Error in the third...
|
by: JJ |
last post by:
Hi,
I created a DataAdapter, connection object and dataset generated from
DataAdapter by dragging DataAdapter compenent to win form. Now in the code
behind I want to use that DataAdapter. I go...
|
by: TJ Doherty |
last post by:
Need help understanding the following please:
When I am creating a project and code my connection using Dim connectString
As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data...
|
by: Doug Bell |
last post by:
Hi,
I thought I had this sorted this morning but it is still a problem.
My application has a DataAccess Class.
When it starts, it:
Connects to a DB (OLE DB)
If it connects it uses an...
|
by: Franklin M. Gauer III |
last post by:
In VS2003 I used to be able to drag a SQL Server table from Server Explorer
onto my webservice (in design mode) and it would automatically create a
DataAdapter for me. This doesn't work in VS2005...
|
by: Franklin M. Gauer III |
last post by:
I create a simple DATAADAPTER in a webservice project. It creates the
UPDATE, INSERT, DELETE commands for me - no problem.
In vS2005 it creates these commands as RESOURCES in the RESX file (i.e....
|
by: Rich |
last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn)
dim tblx As New DataTable
da.Fill(tblx) '--works OK up to this point
da.UpdateCommand = New SqlCommand
da.UpdateCommand.Connection =...
|
by: Emil |
last post by:
I've created a very simple data base in Microsoft Access 2003. It consists
of only one table called "Students" and it contains 2 information about each
student: id-student and name.
When I try...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |