|
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
|
|
|
|
|
|
thank for your advice Mackay
|
|
|
|
|
wow!, i am amazed at how micro$oft can charge for sql licences. My qusetion is pretty simple but no one can answer it!
If i am using asp.net via sql server 2005, so imagine 20 people via the intranet or lan accessing the same page. How many CAL's do i need?
It should be pretty trival, but i can't find the answer anywhere?
Microsoft say you need a cal for every user or device making a direct connection to sql server or even indirect connections, like pooling or multiplexing. See this page http://www.microsoft.com/sql/howtobuy/multiplexing.mspx[^]
I know of certain application like Cimplicity by GE Fanuc that do this, ok they are running scripts as part of a user action but still 20 people could be making the same connection using the same CAL, surely this is illegal?
Why it is ok for some and not other -- are GE in bed with Microsoft!!
thanks -- just standing on my soap box
can anyone give my an answer?
|
|
|
|
|
|
But intranet is not internet, its an internal network. Yes you could say that for big companies having customers connect to their website and using the database via asp.net. But what about internal customers and employees?
What about the small that can't afford to pay for the processor licensing model!
|
|
|
|
|
Use SQL Express or move to one of the other free alternatives (MySql, etc.)
Having used SQL Server for many years, I found it fairly cheap for what it does. It is the only server I have that has never 'burped'. We used to buy CALs many years back but, switched to per processor when SQL 2000 came out. At 2 processors running for 6 years with 30+ active users/devices that comes out to about $50 bucks per user per year with no license managment headaches. I am not even counting our Internet hits. Granted, coming up with the $10K in the beginning was tough.
I think you will find the pricing competitive with Oracle and other mature datbases.
|
|
|
|
|
Hi all,
I have a problem regarding data bindings. I am using Ms Access database and I have an application which loads the tables in datagrids and textboxes.
I used joins since there are relations between tables. For example I have a table called "Alterations" and in this table there is a field called "Client" which brings the name of the client from the table "Clients" .
When running the application an error occurs stating that "no value given for one or more required parameters"
Some one knows what this error is please??
Thanks alot
|
|
|
|
|
check syntax or can u display ur problem here??
|
|
|
|
|
My problem is that when I run the application an error occurs stating that "no value given for one or more required parameters"
And I am not understanding the error!
|
|
|
|
|
check syntax if any parapmeter is without value.
when u call method and possiblity u forgot to give value for parameter.
|
|
|
|
|
Can u pls tell me, wether following SQL string format is correct or not.
textWord.text,comboCat.text are string variables of C#.
indexInCategoryTable and SubCategoryNo are integer variables.
"select * from Words where
word = N'"+textWord.Text+"' and
CategoryTableName = '"+comboCat.Text+"' and
IndexInCategoryTable = 'indexInCategoryTable' and
SubCategoryNo = 'SubCategoryNo'";
|
|
|
|
|
cshivaprasad wrote: Can u pls tell me, wether following SQL string format is correct or not
No. You should use parameters rather than inject values into the query - See SQL Injection Attacks and Tips on How to Prevent Them[^] unless you want your database attacked by a rampaging mob of mallicious attackers.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Procedure: We have two tables namely table A and Table B. Table A contains a field called ID Table B contains field ID and field 1,field 2,field 3.The procedure is to pick value from table A ID field, increment it by 1 to it and update the table A, then insert data into table B with this incremented value and other data.
Problem: When multiple concurrent users perform updation/insertion of data into table A,table B duplicate IDs are getting created in table B even though the statements are written within ADO.NET BEGINTRANSACTION,COMMIT/ROLLBACK.
Thanks
Mahesh
-- modified at 2:11 Tuesday 9th May, 2006
|
|
|
|
|
Study up on Holding Locks and SET TRANSACTION ISOLATION LEVEL in SQL Server Books Online.
----------
There go my people. I must find out where they are going so I can lead them.
- Alexander Ledru-Rollin
|
|
|
|
|
Ex: SELECT DAY(GETDATE())
its display 9 but i need to show tuesday.
can anybody help?
raj
|
|
|
|
|
i found out myself. thanks
the answer is below:
SELECT datename(dw,getdate())
raj
|
|
|
|
|
Hi everybody
please i want to know how to index a column actualy a foreing key
i have a foreing key who megrate from a table to an other one
but i have to index the foreing key in the second table
is it a possibility to do that in sql server ??
try to be good if you can't be the best
|
|
|
|
|
If you want to add a foreign key constraint:
ALTER TABLE dbo.tblForeignTableName
ADD CONSTRAINT keyConstraintName
FOREIGN KEY(fldForeignFieldName)
REFERENCES dbo.tblPrimaryTableName(fldPrimaryFieldName)
ON UPDATE CASCADE
ON DELETE CASCADE
----------
There go my people. I must find out where they are going so I can lead them.
- Alexander Ledru-Rollin
|
|
|
|
|
Hi ,
as you know in sql server we have just datetime we don't have date & time
so when i want to recuperate the date of something in ma textbox i recuperate also the time
can you giveme a solution ??
thank you very much
try to be good if you can't be the best
|
|
|
|
|
When you recover this value from the database and store it in a datetime variable, you can check the date part by calling:
datevariable.Date;
That's it, well pretty much hehe, this actually returns the date with the time part set to 00:00:00
to put in a text box, you can simply call something like.
datevariable.ToShortString();
or
datevariable.ToString("MM/dd/yyyy");
you should change the formatting as you see fit.
I hope I addressed what you are looking for .
daniero
|
|
|
|
|
thnx man , i will try the first because i tried the second before & it dosen't work
thanks a lot
try to be good if you can't be the best
|
|
|
|
|
Hello Coders
In my 2.0 Application 2 DataSets. Here 2 DataSets tables are same. Let us assume the first DataSets Table is one, Second DataSet is also having one Table. both tables are same Tables.
DatasetA.table[0].rows.count=1000
DatasetB.table[0].rows.count=0
DatasetB.Tables[0].Merge(DatasetA.Tables[0]);
DatasetA.table[0].rows.count=1000
DatasetB.table[0].rows.count=1000
But i want this changes should be reflected to database table.
Here where i done the Mistake,
<br />
cnn = new SqlConnection("server=figmdtest01;database=CPOPMFigMD04Dev25ACA;uid=CPOPM;pwd=CPOPM");<br />
cnn.Open();<br />
<br />
cnn1 = new SqlConnection("server=(local);database=Master;uid=sa;pwd=''");<br />
cnn1.Open();<br />
<br />
cmd = new SqlCommand("select PatientProfileId,First,Middle,Last,SSN,Birthdate,Zip,MedicalRecordNumber from cus_FigMD_PatientSearch", cnn);<br />
<br />
SqlDataAdapter dataAdapt1 = new SqlDataAdapter(cmd);<br />
<br />
DataSet ds11 = new DataSet();<br />
dataAdapt1.Fill(ds11);<br />
<br />
cmd2 = new SqlCommand("select PatientProfileId,First,Middle,Last,SSN,Birthdate,Zip,MedicalRecordNumber from demo", cnn1);<br />
<br />
SqlDataAdapter dataAdapt3 = new SqlDataAdapter(cmd2);<br />
<br />
DataSet ds33 = new DataSet();<br />
dataAdapt3.Fill(ds33);<br />
MessageBox.Show(ds33.Tables[0].Rows.Count.ToString()); <br />
ds33.Tables[0].Merge(ds11.Tables[0]);<br />
MessageBox.Show(ds33.Tables[0].Rows.Count.ToString()); <br />
ds33.AcceptChanges();<br />
MessageBox.Show(ds33.Tables[0].Rows.Count.ToString()); <br />
dataAdapt3.S.Update(ds33.Tables[0]);<br />
MessageBox.Show(ds33.Tables[0].Rows.Count.ToString()); <br />
anybody anysounds, plz help me will be appriciated greatly
regards
Rupesh
|
|
|
|
|
I have installed MSDE software in one machine. it's running fine. Daily i am testing. if's working fine. But two weeks later, when i am trying to start MSSQL Server, It's not running. MSSQL Server immediately turn to off mode. what happened to the software? Please give any suggestions.
knarasimharao
|
|
|
|
|
Hi guys
The question is simple. Is is worth starting to learn SQL server 2000 now?
I've been programming to retrieve data from databases for a while & i'm currently familiar with the db design concepts & SQL.
Do u think what i learn about SQL 2000 would be of any use for version 2005? Are the changes so drastic to make my SQL 2000 knowledge useless?
Thanx for any tips
|
|
|
|