|
Just to develop windows application in vb.net2.0, want to use MS Access.
jr
-- modified at 23:50 Friday 24th February, 2006
|
|
|
|
|
You usually write that yourself, wrapping tables, views, records, and stored procedures in classes that will make it easier to for your main app to reuse the database.
There's no generic data access layer for every application. There are DAL Frameworks that make it easier to write a DAL, but nothing will completely wrap your database for you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
basically i have 4 columns in the table called Forum. There are TopicId, Subject, Date and RelTopicId. For every new thread and reply on the thread, the TopicId is unique, which means for every record saved has an unique ID. For every new thread the RelTopicId will set to 0 and for every reply on the topic will set to the TopicId of the thread. This is how it look like.
TopicId Subject Date RelTopicId
1 asp 2/12/2006 11:40:40AM 0 (This is a new thread)
2 RE asp 2/12/2006 11:56:10 PM 1 (A reply on subject asp)
3 RE asp 2/12/2006 12:45:12 PM 1 (A reply on subject asp)
4 Vb.net 2/13/2006 13:40:54 PM 0 (A new thread)
5 RE Vb.net 2/13/2006 13:59:51 PM 4 (A reply on Vb.net)
6 RE asp 2/14/2006 10:20:30 AM 1 (A replt on asp)
TopicId 1 and RelTopicId 0 is the parent, and all the RelTopicId 1 is the child to the Parent which is TopicId 1."note all RelTopicId = 0 is a new thread"
here is the sql statement to retrive data
select * from Forum where Date >='2006-2-12' and Date <'2006-2-13 and TopicId = "0"
this is to get the parent.
my question is how to retrive the parent and the child data. This is to get the Parent(TopicId = 1, RelTopicId = 0) and the child which is (all RelTopicId = 1)
i have try this "select * from Forum where Date >='2006-2-13' and Date <='2006-2-14 and TopicId = "0" and RelTopicId = TopicId"
i got no luck. any help appreciate thanks.
|
|
|
|
|
You have to use a JOIN.
SELECT parent.*, child.*
FROM Forum AS parent
INNER JOIN Forum AS child ON parent.TopicId = child.RelTopicId
WHERE [Date] >= '2006-02-13'
AND [Date] <= '2006-02-14'
AND parent.RelTopicId = 0
Please note that it is bad practice to use SELECT * in production code. Its find for doing quick queries in the Query Analyzer, but not here. Also be aware that as it stands, because of the use of the * there will be duplicate column names because parent and child refer to the same real table. You may want to write something like:
SELECT parent.TopicId AS parent_TopicId,
parent.Subject AS parent_Subject,
...
child.TopicId = child_TopicId,
...
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
I have some C# code that is handling some sql calls using stored procedures.
the way I am currently handling things I am opening and closing the connection for each call to the stored procedure, like this:
<br />
com.Connection.Open();<br />
com.CommandText = "exec sp_thing 0";<br />
com.ExecuteNonQuery();<br />
com.Connection.Close();<br />
<br />
com.Connection.Open();<br />
com.CommandText = "exec sp_thing 1";<br />
com.ExecuteNonQuery();<br />
com.Connection.Close();<br />
<br />
com.Connection.Open();<br />
com.CommandText = "exec sp_thing 2";<br />
com.ExecuteNonQuery();<br />
com.Connection.Close(); <br />
I am having to do this because each call to the procedure is handling close to 300,000 records at a time.
My question (for any ado.net masters out there) is if this is more efficient (memory usage-wise) than declaring a new connection every time, which would allow me to set a new timeout every time, but this seems to be a much cleaner use of code. Am I correct in thinking that i may already be using it the best way?
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Do this:
private void MyMethod(string MyQuery)
{
com.Connection.Open();
com.CommandText = MyQuery;
com.ExecuteNonQuery();
com.Connection.Close();
}
Then call that method like this
MyMethod("exec sp_thing 0");
MyMethod("exec sp_thing 1");
MyMethod("exec sp_thing 2");
You could also process everything and then close the database and the very end using try-accepts.
|
|
|
|
|
I cant believe I spaced doing that.... Im usually a littl enutty about reusable code.
I have another question. I know that when data is put ina a dataset, it is basically being stored in memory as XML. This was the root off my original problems with this app because the shear volume of data, coupled with being used in a dataset, ate up all of the memory on the server and crashed the app.
I was wondering, If anyone happens to know, if DataTables use an xml layout to store that data, or perhaps something simpler (and less memory intensive)?
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Vodstok wrote: I was wondering, If anyone happens to know, if DataTables use an xml layout to store that data, or perhaps something simpler (and less memory intensive)?
Data reader is the most efficient way to get data from a database. Datasets and datatables are relatively costly.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Technically
com.Connection.Open();
com.CommandText = "exec sp_thing 1;exec sp_thing 2;exec sp_thing 3";
com.ExecuteNonQuery();
com.Connection.Close();
is the most efficient, but it only really makes a difference if the statements batched together are relatively fast. If the statements return a lot of data or are slow to execute, managing the connection isn't going to make a lot of difference.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
thanks for the responses. We (okay, one of the other programmers) discovered a REALLY quick way to upload what we need (although It was nice to get my questions answered, since that is something any programmer who uses sql should know)
He stumbled over the BULK INSERT statement. We devised a way for the users to uppload the MASSIVE csv files (almost 300,000 records, and over 20 columns) to upload the file to the webserver's filesystem, and for the sql server to then use bulk insert to upload the file to the db (which takes roughly 10 seconds, as opposed to the 8-10 minutes the old fashioned way worked)
If i get a chance to weed out any potentially compromising information, I will post how we accomplished this. it is really pretty cool.
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Hi
I have two store procedur for update data in two table.For example t1,t2.
t1 is realeted with t2 and t1 have id_n(pk),name columns,t2 have id_n(fk),tel(ok).But the problem is if i add data to t1 and bye some reason(exception) i don't add to t2.I will not have related name with number how to solv this problem?
1.If i make one store procedure from this two.
2.If exist pleas tell me.))
good bye
|
|
|
|
|
Yes, you can put multiple INSERT statements into a stored procedure. You can then put a BEGIN TRANSACTION before the first INSERT statement, after each INSERT check for an error, if there is an error then ROLLBACK TRANSACTION and exit the stored procedure. If there is no error then at the end of the stored procedure COMMIT TRANSACTION .
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
how to check for errors???
|
|
|
|
|
At the start put:
DECLARE @currentError int After each insert put a
SELECT @currentError = @@ERROR;
IF @currentError <> 0
BEGIN
ROLLBACK TRANSACTION
RETURN
END
This would all be better in a stored procedure though.
Does this help?
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Super thank u!Best regards
|
|
|
|
|
hello
plz help me i want to add some new rows in database file this file has only one column which is numeric. i am implementing it in c# how i will add and how i will update my table.
like if i want to enter random numbers in this field upto 500 means i have to create 500 new rows in my database file how i will implemet it.
plz reply as soon as possible
-- modified at 9:46 Friday 24th February, 2006
|
|
|
|
|
hi look here is all answare of u question!))
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_raddata/html/7dc75b15-4d55-47a2-afe4-4e5fb0640c3a.htm
|
|
|
|
|
its not working plz tell me soonnnnnnnnnnn
|
|
|
|
|
Look at this.by this code u can make 500 new rows
For exp your table name is t1 and it is located in a dataset dataSet1
dataRow newRow;
For(int i=0;i<500;i++)
{
newRow=dataSet1.t1.newRow();
newRow[num]=x;
dataSet1.t1.Rows.Add(newRow);
}
Num is the name of your field in your db and x is a number.
m.t.
|
|
|
|
|
hi
How i can give data on this varable "@intA"
set @intA=select max(job_id) from maininfo is not work i need to take max values of this tabel how to do it???
good bye
|
|
|
|
|
|
ok but now i have bigger problem why is not work???
CREATE PROCEDURE sp_addTel
--@JI varchar(30),
@MB bigint,
@TG smallint,
@MF smallint,
@var1 int output
as
set @var1=(select max(job_id) from maininfo)
insert into TeleInfo(job_id,mobil_db,tele_firm,mobil_firm)
values(@var1,@mb,@tg,@mf)
GO
|
|
|
|
|
papa1980 wrote: but now i have bigger problem why is not work???
What do you mean "not work"? That is such a vague statement.
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
try this :
CREATE PROCEDURE sp_addTel
(
--@JI varchar(30),
@MB bigint,
@TG smallint,
@MF smallint,
@var1 int
)
as
select @var1= max(job_id) from maininfo
insert into TeleInfo(job_id,mobil_db,tele_firm,mobil_firm)
values(@var1,@mb,@tg,@mf)
GO
|
|
|
|
|