Click here to Skip to main content
15,916,371 members
Home / Discussions / Database
   

Database

 
QuestionSQL server 2000 Some friend help me Pin
AnhTin9-May-06 19:02
AnhTin9-May-06 19:02 
AnswerRe: SQL server 2000 Some friend help me Pin
Colin Angus Mackay9-May-06 21:38
Colin Angus Mackay9-May-06 21:38 
QuestionCan anyone answer my Query? Pin
Deepasubramanian9-May-06 17:29
Deepasubramanian9-May-06 17:29 
AnswerRe: Can anyone answer my Query? Pin
Chinchu Raj S9-May-06 21:40
Chinchu Raj S9-May-06 21:40 
AnswerRe: Can anyone answer my Query? Pin
Colin Angus Mackay9-May-06 22:02
Colin Angus Mackay9-May-06 22:02 
QuestionSQL Server 2000, uniqueidentifier (guid) PK columns, and ADO.NET 2.0 Pin
Jon Rista9-May-06 16:42
Jon Rista9-May-06 16:42 
AnswerRe: SQL Server 2000, uniqueidentifier (guid) PK columns, and ADO.NET 2.0 Pin
Jon Rista10-May-06 8:08
Jon Rista10-May-06 8:08 
QuestionNeed advice for Parent Child insert in transaction mode Pin
sandi antono9-May-06 4:28
sandi antono9-May-06 4:28 
I have Parent child table as decribe below:


Parent Table name = TESTPARENT
1. counter bigint isIdentity=Yes Increment=1 Seed=1
2. customer nChar(10)


Child Table name = TESTCHILD
1. counter bigint
2. qty numeric(3,0)



I want to insert new record with code below:


void button1_Click(object sender, EventArgs e)
{
// Define object to catch @@indentity
object myCounter;


// Connect to database & open
myConnection = new SqlConnection("Data Source=54ND1\\SQL2005;Initial Catalog=Axioma;User ID=sa; Password=sandi");
myConnection.Open();


// define transaction
SqlTransaction myAtom = myConnection.BeginTransaction();
SqlCommand myAtomCmd = myConnection.CreateCommand();
myAtomCmd.Transaction = myAtom;


// Start insert to database with transaction mode
try
{
// Insert parent new record
myAtomCmd.CommandText = string.Format("insert into TESTPARENT (customer) values ('{0}')", tbCustomer.Text);
myAtomCmd.ExecuteNonQuery();

// Get Indentity
myAtomCmd.CommandText = "SELECT @@identity from testParent";
myCounter = myAtomCmd.ExecuteScalar();


// insert child new record
myAtomCmd.CommandText = string.Format("insert into TESTCHILD (counter, qty) values ('{0}', {1})",

Convert.ToInt64(myCounter.ToString()), tbQty.Value);
myAtomCmd.ExecuteNonQuery();

// Commit transaction
myAtom.Commit();
}
catch
{
myAtom.Rollback();
MessageBox.Show("Data not inserted");
}
}


I already try with 2 workstation and 1 server, that code working well (not duplicate in parent and insert right relation

child parent record in child table ).
If, i run with many many user, I am not sure that code will stay stable.
Please advice, that code is the right way to archieve parent child relation insert table??
I using C# and SQl Server 2005


Thank,s and regards OMG | :OMG: OMG | :OMG:
AnswerRe: Need advice for Parent Child insert in transaction mode Pin
Paddy Boyd9-May-06 5:01
Paddy Boyd9-May-06 5:01 
GeneralThank's Pin
sandi antono9-May-06 5:27
sandi antono9-May-06 5:27 
QuestionMicrosoft sql server 2005 licensing query Pin
Fu Manchu9-May-06 3:20
Fu Manchu9-May-06 3:20 
AnswerRe: Microsoft sql server 2005 licensing query Pin
Michael Potter9-May-06 3:55
Michael Potter9-May-06 3:55 
GeneralRe: Microsoft sql server 2005 licensing query Pin
Fu Manchu9-May-06 4:22
Fu Manchu9-May-06 4:22 
GeneralRe: Microsoft sql server 2005 licensing query Pin
Michael Potter9-May-06 5:01
Michael Potter9-May-06 5:01 
Questionjoins Pin
PuccPukka9-May-06 0:51
PuccPukka9-May-06 0:51 
AnswerRe: joins Pin
albCode9-May-06 2:34
albCode9-May-06 2:34 
GeneralRe: joins Pin
PuccPukka9-May-06 3:29
PuccPukka9-May-06 3:29 
GeneralRe: joins Pin
albCode9-May-06 3:44
albCode9-May-06 3:44 
QuestionQuery String Pin
cshivaprasad8-May-06 21:30
cshivaprasad8-May-06 21:30 
AnswerRe: Query String Pin
Colin Angus Mackay8-May-06 22:37
Colin Angus Mackay8-May-06 22:37 
QuestionMultiple user inserting table at same time Pin
MaheshSharma8-May-06 20:11
MaheshSharma8-May-06 20:11 
AnswerRe: Multiple user inserting table at same time Pin
Eric Dahlvang9-May-06 3:16
Eric Dahlvang9-May-06 3:16 
Questionhow to get name of the day in SQL2000 Pin
isroavi8-May-06 17:24
isroavi8-May-06 17:24 
AnswerRe: how to get name of the day in SQL2000 Pin
isroavi8-May-06 17:33
isroavi8-May-06 17:33 
Questionhow can i index the column ?? Pin
Mohammed Amine8-May-06 13:12
Mohammed Amine8-May-06 13:12 

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.