|
Personally, I would have written this as
rd=com.ExecuteReader();
while(rd.Read())
{
} Rather than do all that rd.HasRows() followed by a do{}while() but I don't see how this would make it faster unless HasRows is particularly slow.
When you timed the data transfer using a SqlAdapter did you include the time to perform all the other actions where you have indicated // some code goes here ?
Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums
|
|
|
|
|
hi,
the action on the datareader is just pick up the datas and save them but on my machine with about 2.6 GHZ i dony think the code makes it sliw,is it possible that my sql query wich has where clause makes the transactions slow?
|
|
|
|
|
UAU wrote:
is it possible that my sql query wich has where clause makes the transactions slow?
Possibly, but it does not explain that your test using a SqlDataAdapter was faster (I am assuming you performed exactly the same query). It should have been slower because using the SqlDataAdapter makes a copy of the data in memory (in the DataSet object) before you can pick up the data and save them.
What does your SQL Query do?
Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums
|
|
|
|
|
hi,
this is the complete source code,but to tel you the truth i didnt use the same query with my SqlDataAdapter i made a simple select query with no where clause.
com.CommandText = "select * from general where parent = @id order by menuindex desc ";<br />
rd=com.ExecuteReader();<br />
if(rd.HasRows)<br />
{<br />
rd.Read();<br />
do<br />
{<br />
if(rd.GetBoolean(2))<br />
AddSeperatorDownLoad(cur,0);<br />
else<br />
AddNodetoNodeDownLoad(cur,0);<br />
SetChild(cur.Nodes[0],rd);<br />
list.Push(cur.Nodes[0]);<br />
}while(rd.Read());<br />
}<br />
rd.Close();<br />
if(cur.Nodes.Count > 0)<br />
{<br />
com.CommandText="select * from popup where menuid = @id ";<br />
if(con.State == ConnectionState.Closed)<br />
con.Open();<br />
rd=com.ExecuteReader();<br />
rd.Read();<br />
SetPopup(cur,rd);<br />
}<br />
rd.Close();<br />
if(curtag.menuItem != null && curtag.menuItem.GeneralSetting.IsPage)<br />
{<br />
curtag.menuItem.GeneralSetting.Page=new PageSetting();<br />
com.CommandText="SELECT Title, KeyWord, IsGuideLine, Description "<br />
+" FROM Page where menuid=@id";<br />
rd=com.ExecuteReader();<br />
if(rd.HasRows)<br />
{<br />
rd.Read();<br />
curtag.menuItem.GeneralSetting.Page.Description=(string)rd["Description"];<br />
curtag.menuItem.GeneralSetting.Page.IsGuideLine=(bool)rd["IsGuideLine"];<br />
curtag.menuItem.GeneralSetting.Page.KeyWords=(string)rd["KeyWord"];<br />
curtag.menuItem.GeneralSetting.Page.Title=((string)rd["Title"]).Replace("Karmania Media ::","");<br />
curtag.menuItem.GeneralSetting.Page.PageContent"";<br />
}<br />
rd.Close();<br />
}<br />
|
|
|
|
|
Okay, here are some general tips - They may or may not improve the speed
1. Don't use SELECT * because if your data model changes on the database then your code could break if the position of columns changes. You should always send a list of the columns you need that way if there are any additional columns in the table that you don't need to don't waste time retrieving them and you always know the order the columns will arrive in.
2. If the table is large you may wish to consider indexing the columns that are referenced in the WHERE and ORDER BY clauses. However, if you do a lot of INSERT s on the table you may have to balance the needs of inserting quickly over retrieving quickly. Adding indexes slows down INSERT , UPDATE and DELETE operations because it has to modify each affected index as well as the table.
3. You can replace
if(rd.HasRows)
{
rd.Read();
do
{
}while(rd.Read()); with
while(rd.Read())
{
} which removes the redundant rd.HasRows call. Because the first call to rd.Read() will return false anyway if there are no rows in the result set the rd.HasRows can be removed if the check on the while is moved to the top of the loop rather than at the bottom of the loop
I hope this helps.
Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums
|
|
|
|
|
hi,
i found something ,when i use sqldatareader the recieved data is more than 1 MB that the real data is less than 100KB ,is it possible that when i use datareader for many transactions i have too much overhead in recieved data?
|
|
|
|
|
I am trying to access SQL Server 2000 across a personal network. I am using the following connection string:
"Data Source=\\GUITARCHORD\LABTRACK;Initial Catalog=LabTrack Server;Integrated Security=SSPI;User ID=someone,Password=pass"
The name of the computer is GUITARCHORD, the name of the SQL Server instance is LABTRACK, and the name of the database I am trying to connect to is LABTRACK SERVER. The user id and password are the Windows Login for the computer that SQL Server is running on. SQL Server is running but I can only access it if I am working on the same computer. I am using VB.NET to try to access this server. I am getting the following error message:
"SQL Server does not exist or access denied."
I have tried every thing I could think of for a connection string, including using TCP/IP settings. Any suggestions would be extremely helpful.
------------------------
ColdWaterBlue - Rock On
|
|
|
|
|
|
I actually just figured it out myself. The two front slashes are not needed, but you need to add a user to the SQL Server (in my case, add the 'Guest' user) and give it administrative rights over the database. The User ID and Password are no longer needed, since the Integrated Security uses a trusted connection. Thanks anyway.
------------------------
ColdWaterBlue - Rock On
|
|
|
|
|
|
Hello
In C# windows forms i have some TextBox that are binding to my Dataset.I want to get the current row to set my DataRow for delete the current row ,for using objDataRow.Delete() method
How i can do it ?
|
|
|
|
|
Can someone show me charp code to save and get an image data from/in a mdb database.
Please i don't need SQL code or not charp code, thanks.
|
|
|
|
|
Sasuko wrote:
Can someone show me charp code to save and get an image data from/in a mdb database
What is charp code??? You mean C sharp (C#) programming language??? I used to do this method in VB.net. The concept is store the path of the picture in an Access database, so when you call the record you can use the function Image.FromFile("Picture path") to load the picture on the form. It is better to use this method in order to save your database storage space.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
I need to store date instead.
|
|
|
|
|
use #12-12-2004# , it might help to insert date
|
|
|
|
|
Guys, any free OLAP grid for ASP.NET apps that you'd recommend? (Yes, Crystal Reports Designer comes with Visual Studio.NET - but not OLAP grid)
Norman Fung
|
|
|
|
|
Hi, just downloaded NHibernate and playing with it. I ran into this problem when I tried to persists my very first object to database:
"NHibernate.ADOException: Could Not Save Object --> No Persister for SimpleNHibernate.User"
Here's code fragment:
<br />
namespace SimpleNHibernate<br />
{<br />
<br />
class Tester<br />
{<br />
<br />
[STAThread]<br />
static void Main(string[] args)<br />
{<br />
User usr;<br />
<br />
Configuration config = new Configuration();<br />
ISessionFactory factory = config.BuildSessionFactory();<br />
ISession session = factory.OpenSession();<br />
ITransaction transaction = session.BeginTransaction();<br />
<br />
try {<br />
config.AddClass(typeof(SimpleNHibernate.User));<br />
<br />
for(int i=0; i<50; i++) {<br />
usr = new User();<br />
usr.Id="user" +i;<br />
usr.UserName = "user" +i;<br />
usr.Password = "testing";<br />
usr.EmailAddress = "testing@testing.com";<br />
usr.LastLogon = DateTime.Now;<br />
<br />
session.Save(usr);<br />
session.Flush();<br />
<br />
Console.WriteLine(i);<br />
}<br />
<br />
transaction.Commit();<br />
<br />
} catch(Exception ex) {<br />
transaction.Rollback();<br />
Console.WriteLine(ex);<br />
Console.WriteLine(ex.Message);<br />
} finally {<br />
if (session!=null) {<br />
try {<br />
session.Close();<br />
} catch(Exception ignored) {<br />
}<br />
}<br />
}<br />
<br />
return;<br />
}<br />
}<br />
}
Seems like everyone is suspecting that the problem has to do with mapping file [^]... But, the error happens when:
session.Save(usr);
Yes yes, I have embedded my mapping file User.hbm.xml with the assembly so ...
I have also tried to explicitly specify mapping file by adding to nhibernate configuration section of my application config file:
add key="mapping file" value="User.hbm.xml" (bracket ommited..)
Not much luck...
btw, this is a sample (with a bit of modification...) from The Official QuickStart Guide
Thanks in advance.
Norman Fung
Norman Fung
|
|
|
|
|
hi,
i just want retrive schema of Sql Server 2000 database,and using ADOX for that. i got an error when try to iterate through KEYS Collection :
com error :-
datasource null etc..
any alternate method to get KEYS of a Table USING ADOX
by
baijumax
|
|
|
|
|
hi,
i was going to use the ibuyspy example of registering a new user but for some reason my version of the code will let duplicate emails into the database?? im not sure why??
Any way I wondered if any of you guys could point me in the right direction regarding registering a new user page? My login page works fine ...but this register page is giving me a headache!!
Thanks in advance!
Jetset
|
|
|
|
|
jetset32 wrote:
my version of the code will let duplicate emails into the database?? im not sure why??
Add a unique constraint to the database column. Then if you attempt an INSERT or UPDATE with a duplicate email then the operation will fail and you can catch the SqlException
Alternatively, you can write a stored procedure that does a check first and returns a success code back if the check passed and the record was INSERTed or UPDATEed.
jetset32 wrote:
but this register page is giving me a headache!!
For details on ASP.NET see the ASP.NET forum. Unless the thing giving you the headache is database related
Do you want to know more?
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums
|
|
|
|
|
My application captures individual data frames from a measuring device and stores them in an Access database via ODBC.
It also has an option to record video (actually web cam) along with the data.
My original thought would be to record the video file as as seperate file, and when the capture has finished, copy the whole file into the database as a longbinary field.
Another way would be to store each video frame along with the data frame that it corresponds to into one database record.
Any suggestions as to which way is better (or other ideas)
Neil
|
|
|
|
|
soundman32 wrote:
to record the video file as as seperate file, and when the capture has finished, copy the whole file into the database as a longbinary field.
What about recording the video as a separate file, and at the end, store the path to that video file in the database?
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I have a datalist and it works fine with the edit up to the point I get the text boxes and can make the changes. then if I click update my two "message.Text" printers show first the Key correctly, and then the other one shows the original first name, not the name which I changed it to. there are no errors or exceptions. I had done the database command two different ways, one is commented out. I'm not sure how far off I am from having this work. Any assistance would be very welcome.
public void Edit_User(object sender, DataListCommandEventArgs e)<br />
{<br />
userList.EditItemIndex = e.Item.ItemIndex;<br />
userList.DataBind();<br />
}<br />
<br />
public void Update_User(object sender, DataListCommandEventArgs e)<br />
{<br />
string txtCustFirstNameEdit = ((TextBox)e.Item.FindControl("txtUserFirstNameEdit")).Text;<br />
string UserKey = userList.DataKeys[e.Item.ItemIndex].ToString();<br />
<br />
message.Text = UserKey;<br />
message1.Text = txtCustFirstNameEdit;<br />
<br />
OleDbConnection userListConnection = new OleDbConnection(@.....");<br />
<br />
//StringBuilder custUpdateBuild = new StringBuilder();<br />
//custUpdateBuild.Append("UPDATE custInfo SET custFirstName = ('");<br />
//custUpdateBuild.Append(txtCustFirstNameEdit);<br />
//custUpdateBuild.Append("') WHERE ID= ('");<br />
//custUpdateBuild.Append(UserKey);<br />
//custUpdateBuild.Append("')");<br />
//string oleUpdateString = custUpdateBuild.ToString();<br />
<br />
string oleUpdateString = "UPDATE custinfo SET custFirstName = "+"'"+txtCustFirstNameEdit+"'";<br />
oleUpdateString += " WHERE ID = " + UserKey;<br />
OleDbDataAdapter userUpdateAdapter = new OleDbDataAdapter();<br />
userUpdateAdapter.UpdateCommand = new OleDbCommand(oleUpdateString, userListConnection);<br />
userListConnection.Open();<br />
userUpdateAdapter.Update(userListDataSet, "custInfo");<br />
userListConnection.Close();<br />
<br />
userList.EditItemIndex = -1;<br />
userList.DataBind();<br />
<br />
<br />
}
|
|
|
|
|
I need help with a problem, I have a field that contains 28 charecters, and I need to truncate the first 12 so that when my view executes it only shows the last 16.
I am running SQL2000 Server and am accessing my data from a ASP/JS Dataform build in Dreamweaver!
Any suggestions?
David
You are only as good as your last project.
|
|
|
|
|
Use SQL SUBSTRING function. E.g.
SELECT SUBSTRING(fieldName, 13, 15) FROM tableName
You can read more about SUBSTRING in SQL Books Online.
|
|
|
|