|
I've been trying to write to a MySQL db with no luck. Selecting the data and filling the dataSet is no problem. But everytime I try to update, delete or insert I get a concurrency violation. Am I just not mapping the columns correctly?
Database: address
Table: contacts
id int(11) not null auto_increment primary key
fname varchar(20)
lname varchar(20)
phone varchar(15)
Here's the code:
/*
* Created by SharpDevelop.
*
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.Odbc;
using System.Data.Common;
namespace mysql
{
/// <summary>
/// Description of MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button btnLoad;
//
//
private OdbcConnection cnn=new OdbcConnection(@"DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=address;USER=root;PASSWORD=system;OPTION=3");
private OdbcDataAdapter da=new OdbcDataAdapter();
private DataSet ds=new DataSet();
private OdbcCommand selectCmd=new OdbcCommand();
private OdbcCommand insertCmd=new OdbcCommand();
private OdbcCommand updateCmd=new OdbcCommand();
private OdbcCommand deleteCmd=new OdbcCommand();
//
//
void MainFormLoad(object sender, System.EventArgs e)
{
this.da.SelectCommand=this.selectCmd;
this.da.InsertCommand=this.insertCmd;
this.da.UpdateCommand=this.updateCmd;
this.da.DeleteCommand=this.deleteCmd;
//
//table mappings
//
this.da.TableMappings.AddRange(new DataTableMapping[]
{
new DataTableMapping("Table","contacts", new DataColumnMapping[]
{
new DataColumnMapping("id","id"),
new DataColumnMapping("fname","fname"),
new DataColumnMapping("lname","lname"),
new DataColumnMapping("phone","phone")
})
});
//
//select command
//
this.selectCmd.CommandText="select id,fname,lname,phone from contacts";
this.selectCmd.Connection=this.cnn;
//
//delete command
//
this.deleteCmd.CommandText="delete from contacts where (id=@id) and
(fname=@fname) and (lname=@lname) and (phone=@phone)";
this.deleteCmd.Connection=this.cnn;
this.deleteCmd.Parameters.Add("@id",OdbcType.Int,4,"id");
this.deleteCmd.Parameters.Add("@fname",OdbcType.VarChar,20,"fname");
this.deleteCmd.Parameters.Add("@lname",OdbcType.VarChar,20,"lname");
this.deleteCmd.Parameters.Add("@phone",OdbcType.VarChar,15,"phone");
//
//insert command
//
this.insertCmd.CommandText="insert into contacts(fname,lname,phone)
values(@fname,@lname,@phone)";
this.insertCmd.Parameters.Add("@id",OdbcType.Int,4,"id");
this.insertCmd.Parameters.Add("@fname",OdbcType.VarChar,20,"fname");
this.insertCmd.Parameters.Add("@lname",OdbcType.VarChar,20,"lname");
this.insertCmd.Parameters.Add("@phone",OdbcType.VarChar,15,"phone");
this.insertCmd.Parameters["@id"].SourceVersion=DataRowVersion.Original;
}
void BtnLoadClick(object sender, System.EventArgs e)
{
this.cnn.Open();
this.da.SelectCommand=this.selectCmd;
this.da.Fill(ds);
this.cnn.Close();
//
this.dataGrid1.DataSource=ds;
this.dataGrid1.DataMember="contacts";
}
}
}
|
|
|
|
|
like, asp:panel, or asp:button, so that i can change the background image or play a sound or something.
You can have the mouse cursor change so there has to be something.
|
|
|
|
|
You'd be better off asking this question in the ASP.NET or Web Developement forums.
You can't do this with server-side code. It'll have to be done in either HTML or client-side JavaScript.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I have a separate form that pops up when a homemade button on my base form is pressed. On this second form, I get some info and save it when the same kind of homemade button is pressed. So now I need to dispose of the second form. But I get an error with regards to disposal of the homemade button when I say this.Dispose() :
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "myButton".
I'm assuming this is because the base form buttons also use "myButton" and now can't get to it?
Is there some way around this?
Thanks again,
Mel
|
|
|
|
|
If you create form2 from form1, you need to do form2.dispose from somewhere in form1. If form2 is opened modally you can doso after the form2.ShowDialog() call (if you're passing results back as a public member/property be sure to retrieve them first).
|
|
|
|
|
I guess I'm not 100% sure how to do this, so here's what I have so far.
On form1:
private void searchClick(object sender, System.EventArgs e)<br />
{<br />
Searching s = new Searching();<br />
s.ShowDialog();<br />
}
Now the second form pops up, the user inputs data I need, and when btnGo is pressed, I need that form to go away. I tried putting the s.Dispose() after the s.ShowDialog() above, but nothing happens. I then tried, under btnGo_Click() on form2 (aka Searching), to get back to form1, but can't get that working properly either. I'm sure I did this wrong (I had the same basic code as under searchClick above). I haven't figured out how to get between classes very well yet, so all help is greatly appreciated.
By the way, I'd love to be able to pass results back as a public member/property, but haven't figured out how to do that yet either (right now I'm saving them in an xml file). If anyone's bored and could give a quick basic example, that would be wonderful!
Anyway, thanks again!!!
Mel
|
|
|
|
|
Have btnGo_click call this.Close(), and searchClick call s.Dispose() after showdialog.
To pass via properties declare them public and assign the return values prior to calling Close(). access them between showdialog and dispose.
|
|
|
|
|
Hello everybody!!!
iam designing a chat application and i have one problem?
--------------------------------------------------------------------------------------
the problem is :
---------------------
i had implemented text transmission in this way .
client sends a message to another client -------->server receives the message------------> send it to the other client by using his already received networkstream.
but i think this method is not practically cause the size of the server increase with logging of clients cause the server store their networkstream in memory during runtime and suppose we have over 1000.000 clients already connected it will leak the resources of the webserver it is installed on and halt the system
so i thought about designing peer to peer application that the client A demands the ip address first from the co-ordinating server and then use direct connection to the client B and begin chatting but the problem i had found in this architecture is the following:
----------------------------------------------
That There are some private addresses on the internet as follows
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255
and for users use DSL their ip addresses are behind NATS or even private addresses can't be seen in the wild on the internet so what do i have to do for making direct connection between clients after getting full information about the remote computer of the other client from the server .
Note:
-------
i had tested the direct connection on the internet with some friends and i found that one from twenty direct connection work with him and the other can't be seen and i had an exception telling me
The Remote host can be resolved or doesn;t found on the internet or the network
something like that in network exception class.
so what can i do to allow this direct connection like most peer to peer applications already used as emule , napster , gnutella or even yahoo messenger and hotmail messenger.
Mess With The Best And Die Like The Rest
|
|
|
|
|
Your problem is multifaceted and will require at least two solutions - or more. For example, in designing a server like you describe you are really creating a message broker or gateway. If Chat I/O is not critical you might consider going connectionless and use UDP. You can still build your own application protocol to handle sequence and drops, and this would let you get around the network stream issue. At the same time with UDP you can use multicast addressing so that one peer can effectively send to a collective group of IP addresses. An example is if you need to bring the server down it would make for decent but not perfect way of letting the bulk of the users know the system is immenently going down. I say decent because trying to reach every single last chat client is prone to all sorts of network issues. But for the most part such a broadcast or multicast mechnism is still useful.
Now the other problem is in a word: security. If you are planning on communicating thru firewalls then you will have to take VPNs and possibly SSL into account. At the same time, if your company has a VPN that end users dial into or access through the Internet, then they would be able to access your server across the enterprise. Indeed the network people at your company can tell you what to expect and you will need to make sure your app meets their requirements.
To start off, concentrate of getting the message brokering piece to be very efficient and work 100% inside your intranet. Make sure you run lost of stress tests. I recommedn writing a couple of test harnesses that pound your broker from both sides with hundreds of connections (use threads). Once you are certain that your broker is working, any remote user with VPN access should be able to see you broker if allowed by network ops. Thus challenge is get the chat client and broker working BEFORE you stroll into the network ops depertment and ask them to open up a firewall port. Chances are that is a non-trivial question that needs executive sponsorship.
Good luck!;)
Mike
|
|
|
|
|
iam sorry i didn't understand anything from what did you said?
But what is a broker ?
and how can i make mulitcasting mechanism.
but is it effective
Mess With The Best And Die Like The Rest
|
|
|
|
|
Hey everyone. I was wondering is there a way to know if the user clicked the Back button in their browser in the page load or anything?
Sincerely,
The Major Rager
|
|
|
|
|
I used Crystal Report 10 for created my report and then i added the report to my project.
I opened the report in V.S.2003 and change it, then i saved it in V.S.2003 too.
V.S.2003 told me that it's Crystal Report version is older than my Crystal Report version, but i saved the changed report in it.
Now when i install the project in a client machine , my report don't work.
My language is V.C#.NET & my project is a windows base.
what can i do ,to solve this problem?
|
|
|
|
|
Hello!
I am trying to create simple window form, and I have
a problem... When I write "using System." at the
beginning of the code, I don't see the namespace
Windows...
Maybe I need to use some DLL's... I just don't
know...
Maybe someone could help me with it?
Thanks in advance!
|
|
|
|
|
Hi there,
You have to ensure that the dll System.Windows.Form.dll is included into ur project.
<< >>
|
|
|
|
|
Where can I check it?
And maybe it is a stupid question, but it is also a .NET Framework dll, right?
Thanks a lot!
|
|
|
|
|
You can check this in the Add Reference dialog....
No stupid question, only stupid answer...
<< >>
|
|
|
|
|
Hi all,
I have datetime field in database. When I am getting records older than
specific date that I passed in parameter I can not get records that
differs only in Time part of the datetime value.
Looks like comparison of Time portion in query failed.
I am using ACCESS database and ADO OleDbCommand. When in debug in Visual Studio QuickWatch clearly can see that the record that am going to get is older than datetime in TimestampParam by 10 sec (for example). If I substract 1 day from the
database field value I am getting the record. It is definetly time
portion comparison failed.
These are some lines from my code to show how I am reading database
OleDbDataAdapter adapter = new OleDbDataAdapter();
myCommand.CommantText = "SELECT [NetLog].* FROM [NetLog] WHERE
Timestamp < TimestampParam"
adapter.SelectCommand = myCommand;
System.Data.DataSet dataSet = new System.Data.DataSet();
int iNumRows = adapter.Fill( dataSet );
I would appreciate any advice
Thanks,
Roman
|
|
|
|
|
Hi,
As you say, it sounds like the time part of DateTime is getting lost somewhere. I am unclear how you are passing this DateTime to your query code; your code snippet uses 'TimestampParam' hardcoded into the query string - what is this? Can you clarify this as I'm trying to reproduce the behaviour.
Regards,
Rob Philpott.
|
|
|
|
|
String myConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""./data/abel.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
OleDbParameter parameter = new OleDbParameter();
parameter.ParameterName = "@TimestampParam";
parameter.Value = DateTime.Now;
OleDbCommand myCommand = new OleDbCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "SELECT [NetLog].* FROM [NetLog] WHERE Timestamp < @TimestampParam";
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.Add(parameter);
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = myCommand;
DataSet dataSet = new DataSet();
int iNumRows = adapter.Fill( dataSet );
Get zero rows when records differ only in time portion,
Thanks
|
|
|
|
|
Hi,
I've boshed together a similiar set up - an access mdb with a DateTime column and a text column with test strings in it, and used similiar code to yours (I have used OleDbDataReader rather than OldDbDataAdapter /DataSet ), and for me the time is working correctly. My time part of DateTime is reaching the query.
I notice that your code is missing a line telling the parameter its type:
parameter.OleDbType = OleDbType.Date;
I'm surprised your not getting type mismatch exceptions thrown without this. I'd certainly include that and try again.
If still no luck drop me a line and I'll send you my code through for comparison.
Regards,
Rob Philpott.
|
|
|
|
|
Thank you, Rob
Eventually I fixed that using your clue about types.
|
|
|
|
|
Hi,
I have a textbox and when the text entered is longer than the length of the box, only the end portion that fits within the textbox is shown. How can I make it so that when someone enters a long string and presses Enter, that the beginning portion shows?
Thanks so much!!!
Mel
|
|
|
|
|
Hi,
You can move the displayed text in a text box so that the beginning is visible by setting the SelectionStart property to zero. I'd suggest attaching this code to the LostFocus (Leave) event so that the textbox displays correctly when you tab out of it. Hitting enter is usually reserved the default button.
Regards,
Rob Philpott.
|
|
|
|
|
Perfect. Thanks so much!
Mel
|
|
|
|
|
When i call the AsinSearch Amazon web service, i get the following error
"An unhandled exception of type 'System.NullReferenceException' occurred in SellerSearch.exe
Additional information: Object reference not set to an instance of an object."
I've narrowed it down to the following piece of code:
ProdInfo = Doc.ChildNodes[1]
["ProductInfo"]
["ThirdPartyProductInfo"];
dsInventory.Tables["tblSellerData"].Rows.Clear();
for (Counter = 0; Counter < ProdInfo.ChildNodes.Count; Counter ++)
{
Details = ProdInfo.ChildNodes[Counter];
DR = dsInventory.Tables["tblSellerData"].NewRow();
DR["Asin"] = Details["BrowseName"].InnerText;
//DR["Asin"] = Details["Asin"].InnerText;
//DR["Price"] = Details["ExchangePrice"].InnerText;
//DR["ListingID"] = Details["ExchangeId"];
//DR["ProductName"] = Details["
dsInventory.Tables["tblSellerData"].Rows.Add(DR);
}
}
ProdInfo is an xmlNode.
The XML is coming through just fine. You can see it by putting the following uri in a browser:
http://xml.amazon.com/onca/xml2?t=webservices-20&dev-t=099CQN95JW6909V9T8R2&AsinSearch=B00005JKDR&type=heavy&offer=Used&offerpage=1&f=xml
I'm stuck and can't figure out what the problem is.
any ideas?
Thomas Barker
|
|
|
|
|