Click here to Skip to main content
15,886,563 members
Home / Discussions / Database
   

Database

 
GeneralRe: decimal data type Pin
hadad23-Feb-07 1:57
hadad23-Feb-07 1:57 
GeneralRe: decimal data type Pin
Krish - KP26-Feb-07 17:17
Krish - KP26-Feb-07 17:17 
QuestionHow to connect C#.Net program to MS Access database? Pin
Sanjeewani17-Feb-07 20:15
Sanjeewani17-Feb-07 20:15 
AnswerRe: How to connect C#.Net program to MS Access database? Pin
Colin Angus Mackay18-Feb-07 0:02
Colin Angus Mackay18-Feb-07 0:02 
Questionhow to get the value from store procedure Pin
Amit Agarrwal17-Feb-07 17:27
Amit Agarrwal17-Feb-07 17:27 
AnswerRe: how to get the value from store procedure Pin
Krish - KP18-Feb-07 17:46
Krish - KP18-Feb-07 17:46 
Questionxml attributes and database representation Pin
spin vector17-Feb-07 6:36
spin vector17-Feb-07 6:36 
QuestionProblems getting a custom mapped table to update Pin
mrorangecat16-Feb-07 8:09
mrorangecat16-Feb-07 8:09 
I'm trying to use the SqlDataAdapter to map 2 of 5 columns into a DataTable object and then update changes made to the local table back to the table in the database. Every time the Update command is called, I get DBConcurrency errors. I know this is not because of an actual concurrency issue because I am the only one accessing this database and I've tried this code in a separate program to isolate it from anything else I might be doing. I've read in a few places that this can be caused by an invalid update string, but I can't figure out what's wrong with mine. The code I'm using is below.

string sc = "";
string uc = "";

// The following chooses the proper select and update
// commands based on the value of MethodNumber. This
// is where I choose the column in the original table
// that I want to work with and call it OrderPoint in
// the local table. SSID is the PK.

if(MethodNumber == 1)
{
sc += "Select SSID, Method1OrderPoint As OrderPoint From OrderPoints";
uc += "Update OrderPoints Set Method1OrderPoint = @OP Where SSID = @SSID";
}
else
{
sc += "Select SSID, Method2OrderPoint As OrderPoint From OrderPoints";
uc += "Update OrderPoints Set Method2OrderPoint = @OP Where SSID = @SSID";
}

// Create a new DataTable and SqlDataAdapter, fairly standard

DataTable TableOp = new DataTable("TableOp");
SqlDataAdapter AdapterOp = new SqlDataAdapter(sc, Connection);

// Add parameters to the Update command. I've checked the
// SqlRowUpdatingEventHandler and these are being passed properly
// at run time

SqlCommand UpdateCommand = new SqlCommand(uc, Connection);
UpdateCommand.Parameters.Add("@SSID", SqlDbType.NChar, 14, "SSID");
UpdateCommand.Parameters.Add("@OP", SqlDbType.Int, 1, "OrderPoint");
AdapterOp.UpdateCommand = UpdateCommand;

// Add the custom table/column mappings. I've tried every conceivable
// permutation for every possible value I can think of to put in these,
// but no luck so far.

DataTableMapping MappingOp = AdapterOp.TableMappings.Add("OrderPoints", "TableOp");
MappingOp.ColumnMappings.Add("SSID", "SSID");
MappingOp.ColumnMappings.Add("Method1OrderPoint", "OrderPoint");
MappingOp.ColumnMappings.Add("Method2OrderPoint", "OrderPoint");

// Fill the schema and the table. These work fine. The TableOp
// looks and behaves exactly as I would expect.

AdapterOp.FillSchema(TableOp, SchemaType.Mapped);
AdapterOp.Fill(TableOp);

// Change TableOp.

foreach(DataRow CurrentRow in TableOp.Rows)
{
CurrentRow["OrderPoint"] = 1;
}

// Here's the update command.

AdapterOp.Update(TableOp);

This throws the following exception:

System.Data.DBConcurrencyException: Concurrency violation: the UpdateCommand affected 0 records.

I've also tried using a DataSet object instead of the single DataTable with no luck.

I'm using Sql Server Express 2005 with Visual Studio 2003. I've also tried using their visual interface for building an SqlDataAdapter and it fails to generate update and delete commands for a mapped table.

Is it even possible to do this, and if not, what exactly is the point of table/column mapping?

Thanks



-Matt
QuestionHow to get a row count when a delete trigger rolls back the transaction? Pin
Keith Worden16-Feb-07 6:03
Keith Worden16-Feb-07 6:03 
QuestionTrigger execution order Pin
theJazzyBrain16-Feb-07 2:18
theJazzyBrain16-Feb-07 2:18 
AnswerRe: Trigger execution order Pin
Pete O'Hanlon16-Feb-07 2:36
mvePete O'Hanlon16-Feb-07 2:36 
GeneralRe: Trigger execution order Pin
theJazzyBrain16-Feb-07 3:14
theJazzyBrain16-Feb-07 3:14 
Questionlist of all the sp_ (built in)procedure Pin
Ankur.Bakliwal16-Feb-07 0:43
Ankur.Bakliwal16-Feb-07 0:43 
AnswerRe: list of all the sp_ (built in)procedure Pin
Pete O'Hanlon16-Feb-07 0:56
mvePete O'Hanlon16-Feb-07 0:56 
AnswerRe: list of all the sp_ (built in)procedure Pin
Krish - KP16-Feb-07 1:13
Krish - KP16-Feb-07 1:13 
QuestionData base Size Pin
Tauseef A15-Feb-07 23:30
Tauseef A15-Feb-07 23:30 
AnswerRe: Data base Size Pin
Krish - KP15-Feb-07 23:40
Krish - KP15-Feb-07 23:40 
Questionfree sql database upload space provider Pin
Ajay R Ojha15-Feb-07 23:03
Ajay R Ojha15-Feb-07 23:03 
Questiondb backup Pin
amilapradeep15-Feb-07 17:11
amilapradeep15-Feb-07 17:11 
AnswerRe: db backup Pin
Colin Angus Mackay15-Feb-07 23:03
Colin Angus Mackay15-Feb-07 23:03 
GeneralRe: db backup Pin
amilapradeep15-Feb-07 23:16
amilapradeep15-Feb-07 23:16 
QuestionClear database contents Pin
Zoltan Balazs15-Feb-07 11:03
Zoltan Balazs15-Feb-07 11:03 
AnswerRe: Clear database contents Pin
-Dr_X-15-Feb-07 11:06
-Dr_X-15-Feb-07 11:06 
AnswerRe: Clear database contents Pin
Member 9615-Feb-07 11:12
Member 9615-Feb-07 11:12 
GeneralRe: Clear database contents Pin
Zoltan Balazs15-Feb-07 11:18
Zoltan Balazs15-Feb-07 11:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.