|
I had asked it, but was not very clear as to what I was trying to do. I have ben all over the web trying to find a way to do this. I found a lot of information on adding a line, but could find nothing to reduce the line count.
Ray
|
|
|
|
|
Hello, I was wondering what would be the fastest way to read from a SQL database. I have a inventory database that populates a listview with various icons depending on the TypeOfEquipment field. Now I did make it use threading when populating the ListView but it was very chopping... performance wise it didn't "freeze" while loading thei nformation, but everytime an item was insert I guess it would try to go to the top and made the way it looked very choppy.
Anyways, right now I read from the database with SqlDataReader. Would putting it in a datalist then reading from there be faster? All that I am pulling from the SQL table is text. There isn't any files or pictures.
|
|
|
|
|
I forgot to mention this was a Windows application.. and I said DataList but I meant DataSet.
|
|
|
|
|
The ONLY way to read from a SQL database, is SQL. An intermediate step is plainly not going to make it go any faster. Perhaps what you need to do is not try to populate all 3000+ rows at once, what if you show the first page full, and, assuming you can't use paging, just populate with the rest, allowing the user to see the first page while it loads, or something similar to that ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Well,
I see what you are saying now.. using a Dataset with a SqlDataAdapter isn't going to make much difference at all vs. a SqlDataReader right? It works fast and great at work since it is on the network but I was wondering if there was a better way...
Since it is an inventory I could make it not load the information.... you know now that I think about it, I have it grouped in the ListView by the type of equipment. I could put a listbox with checkboxes in it on what items to show. So it doesn't load anything onLoad unless the user clicks a checkbox... i think that might be the best way! Thanks!
|
|
|
|
|
Jacob Dixon wrote: using a Dataset with a SqlDataAdapter isn't going to make much difference at all vs. a SqlDataReader right?
It will be worse if you load everything in to the data set first then have the DataAdapter have to convert that in to SQL for the database. Just put it directly in SQL and miss out the middle bit. (As Christian suggested)
|
|
|
|
|
I'm reading from the database and putting into a listview. Not writing to a database. It has to be loaded into something like a datareader or dataset. Last I knew a listview can't read from a database itself
|
|
|
|
|
Jacob Dixon wrote: I'm reading from the database and putting into a listview. Not writing to a database.
Okay...
Jacob Dixon wrote: It has to be loaded into something like a datareader or dataset.
The DataAdapter uses a DataReader. It is simply another level of abstraction. If you want performance then you remove the layers of abstraction. This improves the performance but makes your application more difficult to maintain.
I'm wondering if what you really want is reponsiveness rather than raw response time? Responsiveness is how quickly the user can get on with what they are doing. Response time, on the other hand, is how quickly the operation as a whole takes to complete. Often you can trade a little response time for increase responsiveness. From the users point of view it appears to work faster when in fact it is slightly slower.
|
|
|
|
|
Well, remotely there is a pause when loading 3000 lines... maybe... 20-40 second pause... I think making it not load any items and displaying a list of EquipmentTypes in a checkbox listbox would be better. That way they can check the type of equipment they want (multiple) and it will display it in the listview. They could select multiple ones that list multiple EquipmentTypes in the listview (by Groups). I was just trying to make the pause (or waiting) the user has down to a minimal. But I know data over the internet is something that just can't be fixed by programming sometimes.
|
|
|
|
|
I am trying write a TCP client that connects to a server and requests HTTP packets using the Socket class. The problem I'm having is when I receive a HTTP return code of 400 (Bad Request), the server disconnects me and I have to close my connection as well. Once I close my connection, the Socket class won't let me start another TCP handshake, let alone send any more packets.
Here is my code for the connection:
;
Socket socket;
IPEndPoint hostEndPoint;
string packet;
public void run()
{
TCPConnect();
packet = SendReceive("/signin.aspx", "GET");
if (GetReturnCode(packet) == "400")
TCPReset();
packet = SendReceive("/index.html", "GET");
TCPClose();
}
private void TCPConnect()
{
if (socket == null)
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
hostEndPoint = new IPEndPoint(ipaddr, port);
}
socket.Connect(hostEndPoint);
}
private void TCPReset()
{
socket.Disconnect(true);
socket.Connect(hostEndPoint);
}
private void TCPClose()
{
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
private string SendReceive(string strURI, strMethod)
{
string pcAppend = " HTTP/1.1\r\nConnection: Keep-Alive\r\n\Content-Length: 0\r\n" +
"User-Agent: Mozilla/4.0 (Compatible; MSIE 7.0; Windows NT 5.2; .NET CLR " +
"2.0.50727; .NET CLR 3.0.04506.30; InfoPath.1; .NET CLR 3.5.21022)\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\nHost: " + strIPAddress + "\r\n\r\n";
byte[] pcSend = System.Text.ASCIIEncoding.ASCII.GetBytes(strMethod + strURI + pcAppend);
byte[] bfBuffer = new byte[10240];
socket.Send(pcSend, pcSend.Length, 0);
socket.Receive(bfBuffer, bfBuffer.Length, SocketFlags.None);
return System.Text.ASCIIEncoding.ASCII.GetString(bfBuffer);
} ;
I've been monitoring the commuications with Ethereal. .Net is closing the connection just fine, but it ignores any socket.Connect() calls after the initial connection.
Any ideas?
|
|
|
|
|
It has been a while since I've used sockets (I usually go for the HttpWebRequest/HttpWebResponse classes these days) so this is a bit of a guess based on some hazy memories. It's worth a try, at least.
When you open the socket for the second time you are openning a connection on the existing socket that was shut down. You may need to open a brand new socket in that case. In which case when you shutdown the old socket you might want to set socket=null; to force a new socket to be created when a new connection is requested.
|
|
|
|
|
That worked! Thanks a million
|
|
|
|
|
socket.Disconnect(true); works only on windows XP. You should try to dispose the socket every time and then create a new one.
Natza Mitzi
|
|
|
|
|
Hi
i was create a control to display images and able to zoom on images. now i want to implement panning on it, can anybody help me ?
Here is my full source code :
public class PictureBoxEx : ScrollableControl
{
private Image _image;
private Single _zoom;
private InterpolationMode _interpolationMode;
private Point lastPos;
#region Properties
[Category("Appearance"), Description("The image to be displayed.")]
public Image Image
{
get { return _image; }
set
{
_image = value;
this.UpdateScaleFactor();
this.Invalidate();
}
}
[Category("Appearance"), Description("The zoom factor. Less than 1 to reduce. More than 1 to magnify.")]
public Single Zoom
{
get { return _zoom; }
set
{
_zoom = value;
this.UpdateScaleFactor();
this.Invalidate();
}
}
[Category("Appearance"), Description("The interpolation mode used to smooth the drawing.")]
public InterpolationMode InterpolationMode
{
get { return _interpolationMode; }
set { _interpolationMode = value; }
}
public Point LastPosition
{
get { return lastPos; }
set { lastPos = value; }
}
#endregion
public PictureBoxEx()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
this.AutoScroll = true;
this.Zoom = 1f;
}
private void UpdateScaleFactor()
{
if (this.Image == null)
this.AutoScrollMargin = this.Size;
else
this.AutoScrollMinSize = new Size(Convert.ToInt32(this.Image.Width * this.Zoom + .5f), Convert.ToInt32(this.Image.Height * this.Zoom + .5f));
}
protected override void OnPaintBackground(PaintEventArgs e)
{
}
protected override void OnPaint(PaintEventArgs e)
{
if (this.Image == null)
{
this.OnPaintBackground(e);
return;
}
Matrix mx = new Matrix(this.Zoom, 0, 0, this.Zoom, 0, 0);
mx.Translate(this.AutoScrollPosition.X / this.Zoom, this.AutoScrollPosition.Y / this.Zoom);
e.Graphics.Transform = mx;
e.Graphics.InterpolationMode = this.InterpolationMode;
e.Graphics.DrawImage(this.Image, new Rectangle(0, 0, this.Image.Width, this.Image.Height), 0, 0, this.Image.Width, this.Image.Height, GraphicsUnit.Pixel);
base.OnPaint(e);
}
}
Thanks
|
|
|
|
|
Panning is easy. Just offset the image by a factor that you change as the mouse moves while it is down.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks Christian
but i didn't found correct algorithm to do this, i was write this code to implement this work :
protected override void OnMouseMove(MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
this.AutoScrollPosition = new Point(this.LastPosition.X + (e.X - this.lastPos.X), this.lastPos.Y + (e.Y - this.LastPosition.Y));
}
this.LastPosition = e.Location;
base.OnMouseMove(e);
}
but it does not correct result which i want (please try this and see the result).
can u help me ?
Thanks
|
|
|
|
|
This looks reasonable to me.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Yes, it was worked, but not best result.
do u have a better idea ?
Thanks
|
|
|
|
|
I want to export table data from one database DB1 to another DB2 (table structure matches).
I filled a dataset with one datatable and exported it into an xml-file.
Then I restore the dataset and want to update in DB2 with
a) inserting rows which are (concerning to a key column) not existing in DB2
b) updating existing rows
Part a) works well with a DataAdapter.Update() because all datarows in my
restored datatable have RowState ADDED and an INSERT is done.
Part b) is the problem: The remaining rows should cause an update of the
non-key columns. I call SetModified() for all DataRows to change RowState to MODIFIED.
The DataAdapter.Update() returns that the rows were modified, but it did not
change anything in the DB2. The reason probably is, that the values of the
DataTable columns have not changed and so the update-statement does not include them.
As a work-around, I changed the values of the DataRow items and restored them to the
original values.
Then the update is done.
But this seems not to be the "official" way...
Any better idea? Thanks.
Here's the code:
private void buttonSaveXML_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=TestDataTable.mdb;");
conn.Open();
DataSet ds = new DataSet("test-DS");
OleDbDataAdapter da = new OleDbDataAdapter("select keycol, col1, col2 from table1", conn);
da.Fill(ds, "table1");
ds.WriteXml("test-DS.xml", XmlWriteMode.WriteSchema);
conn.Close();
}
private void buttonReadXML_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=TestDataTable.mdb;");
conn.Open();
DataSet ds = new DataSet("test-DS");
ds.ReadXml("test-DS.xml", XmlReadMode.ReadSchema);
OleDbDataAdapter da = new OleDbDataAdapter("select keycol, col1, col2 from table1", conn);
da.ContinueUpdateOnError = true;
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
cb.ConflictOption = ConflictOption.OverwriteChanges;
DataTable dt = ds.Tables["table1"];
string trace_command = cb.GetInsertCommand(true).CommandText;
int updcount = da.Update(dt);
MessageBox.Show("first da.Update() does INSERT on " + updcount.ToString() + " rows.\n" +
"InsertCommand is: " + trace_command);
for (int index = dt.Rows.Count - 1; index >= 0; index--)
if (!dt.Rows[index].HasErrors)
dt.Rows.Remove(dt.Rows[index]);
dt.AcceptChanges();
foreach (DataRow dr in dt.Rows)
dr.SetModified();
trace_command = cb.GetUpdateCommand(true).CommandText;
updcount = da.Update(dt);
MessageBox.Show("second da.Update() on " + updcount.ToString() + " rows.\n" +
"UpdateCommand is: " + trace_command);
dt.AcceptChanges();
foreach (DataRow dr in dt.Rows)
{
string save = dr["col1"].ToString();
dr["col1"] = "new changed value";
dr.AcceptChanges();
dr["col1"] = save;
}
updcount = da.Update(dt);
conn.Close();
}
|
|
|
|
|
You should not use this solution.
Natza Mitzi
|
|
|
|
|
I thought that also... and asked for better ideas...
|
|
|
|
|
SharpDevelop is participating in the Google Summer of Code this year. It is an opportunity for students to earn 4500 USD over the summer by working on an open-source project. We have created a list of ideas, but you can work basically on anything you want as long as it is relevant to SharpDevelop. You can find the list of ideas and any further information on the SharpDevelop wiki page for the Google Summer of Code. You can submit your application here. If you are not a student or if you do not have enough spare time, you can benefit as well.... share your ideas with us and maybe some student will pick them up and implement them. Feel free to contact us on the forums or via email. Please spread the word and tell your friends about the Summer of Code...
|
|
|
|
|
Please tell your friends that if they want to advertise their events, Code Project accepts advertisements.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
hi,
i got a problem here that is i have a program where is console. i want to call the value from the console and display into windows forms.
for example in console have
int i;
......
i = .....
then i want to get the value for i and display into text box in windows forms.
like textbox1.text = ???????????
may i know how to make it. thanks.
|
|
|
|
|
tyrone0109 wrote: then i want to get the value for i
How is the value for i put into the console?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|