|
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.”
|
|
|
|
|
In public static void Main(string[] args) , use the parameter (args )
Example:
textbox.Text = args[0];
|
|
|
|
|
hi
i want to load my tree of a c# windows based form with all sql server 2005
databases and tables but whenever i call my function to load tables my all databases disappeared and only the tables of master database comes
please help me its very urgent im posting my code under
// it will load databases and tables
public void LoadSQL_DB(TreeNode DB)
{
TreeNode treenode;
SqlCon = new SqlConnection("Data Source= Localhost; Integrated security=True;database=master");
SqlCon.Open();
SqlCom = new SqlCommand();
SqlCom.Connection = SqlCon;
SqlCom.CommandType = CommandType.StoredProcedure;
SqlCom.CommandText = "sp_databases";
SqlDR = SqlCom.ExecuteReader();
int count = 0;
while (SqlDR.Read())
{
treenode = new TreeNode();
treenode.Text = SqlDR.GetString(0);
DB.Nodes[0].Nodes.Add(treenode);
DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)].Nodes.Add("Tables");
DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)].Nodes.Add("Stored Procedurs");
DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)].Nodes.Add("Views");
DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)].Nodes.Add("Roles");
if (DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)].Nodes[count].Text.ToString()== "Tables")
{
LoadSQL_Tables(DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)]);
}
count ++;
}
}// End of LoadSQL_DB...
// function to load sql tables
public void LoadSQL_Tables(TreeNode parentNode)
{
SqlCon = new SqlConnection("Data Source= Localhost; Integrated security=True;database=master");
SqlCon.Open();
SqlCom = new SqlCommand();
SqlCom.Connection = SqlCon;
string nodeName = parentNode.Text;
SqlCom.CommandText = "use "+nodeName + " select * from sys.Tables ";
//SqlCom.CommandText = "select * from sys.Tables ";
SqlDR = SqlCom.ExecuteReader();
while (SqlDR.Read())
{
parentNode.Nodes.Add(SqlDR.GetString(0));
}
}
|
|
|
|
|
I haven't had time to read through all of your code, yet, but two things strike me immediately.
1) Learn to use the 'code block' item (below the text entry box), this preserves the formatting of your code and makes it easier to read.
The code snippets in item 2 use this. You should note the difference.
2) You code would be easier to read in any case if you replace this:
treenode = new TreeNode();
treenode.Text = SqlDR.GetString(0);
DB.Nodes[0].Nodes.Add(treenode);
DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)].Nodes.Add("Tables");
DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)].Nodes.Add("Stored Procedurs");
DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)].Nodes.Add("Views");
DB.Nodes[0].Nodes[DB.Nodes[0].Nodes.IndexOf(treenode)].Nodes.Add("Roles");
with:
treenode = new TreeNode();
treenode.Text = SqlDR.GetString(0);
treenode.Nodes.Add("Tables");
treenode.Nodes.Add("Stored Procedures");
treenode.Nodes.Add("Views");
treenode.Nodes.Add("Roles");
DB.Nodes[0].Nodes.Add(treenode);
I will contact you further when I have had time for more study.
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.”
|
|
|
|
|
You have learned how to use sp_databases .
To solve at least part of your problem, research sp_tables and use it in your LoadSQL_Tables method. As you will see from the code below, you might also need to pass the database name to the method.
*********** WARNING *****************
sp_tables gets views, and some other stuff, as well as tables, if not used properly!!
*********** WARNING *****************
To make things a little easier for yourself, you should think about modifying the flow of your code something like:
while (SqlDR.Read())
{
treenode = new TreeNode();
treenode.Text = SqlDR.GetString(0);
TreeNode tablesNode = treenode.Nodes.Add("Tables");
LoadSQL_Tables(tablesNode, treeNode.Text);
treenode.Nodes.Add("Stored Procedures");
treenode.Nodes.Add("Views");
treenode.Nodes.Add("Roles");
DB.Nodes[0].Nodes.Add(treenode);
count ++;
}
If this works, and I hope it does, it should give you some ideas about how to get the other data you need.
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.”
|
|
|
|
|
Hi
thank you so much Henry for the guide line but i am still having some problem and that is instead of my table's name, the name "master" is coming under the node of master table's node, more over the tables of other databases amd their tables are not coming.. i am very confused ..
the signature of my Load_sqlTable function is now as under
public void LoadSQL_Tables(TreeNode parentNode,string dbname)
is it correct?
regards,
|
|
|
|