|
Hi everyone!
My C# Project is using MySQL stored procedure to execute sql query.
My question is How will I retrieve all rows in select * statement and put in a class? For example.
[Row column]..........[Class 'User' member]
user_name -----> userName
user_id ---------> userID
I do not have idea at all since I am new to this C# and MySQL tandem.
Thank you in advance.
|
|
|
|
|
|
MySqlCommand cmd = new MySqlCommand("ProcName", new MySqlConnection("ConnectoinStringHere")); // ProcName should be the name of the procedure which you want to call
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection.Open();
MySqlDataReader dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
// Now you have all the data in the dataReader. So, you can loop through the datareader like
while (dataReader.Read())
{
string name = dataReader["Name"].ToString(); // this will store the Name (which is a column_name in the database) to a local variable
}
dr.Close();
But it is suggested to not get the full data of a table into the memory unless you really require it.
|
|
|
|
|
HI!
I tried to code a simple tool, that uploads my XML Files to www.meinpaket.de. But each time I try it, I get a 403 Exception.
Can someone explain me, what is wrong here? WebResponse oWebResponse = oWebRequest.GetResponse() is raising the Exception.
Thanks for Help
public class MeinPaketRequest
{
public string TestURL { get; set; }
public string URL { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public bool Test { get; set; }
CookieContainer _cookies = new CookieContainer();
public MeinPaketRequest()
{
this.TestURL = "https://mp-api.mepa-home.de/dealerapi/xml";
this.URL = "https://www.meinpaket.de/dealerapi/xml";
this.Test = true;
this.Username = "Username";
this.Password = "Password";
}
public string Request(string Filename)
{
if (string.IsNullOrWhiteSpace(Filename))
{
Filename = "C:\\Users\\TWGT-KASSE-2\\Desktop\\MeinPaket\\Beispieldateien_042013\\mp_example_30_01_download_orders.xml";
}
XmlDocument xDocument = new XmlDocument();
xDocument.Load(Filename);
foreach (XmlNode oNode in xDocument.ChildNodes)
{
if (oNode.Name == "dataRequest")
{
foreach (XmlNode oNodeRequest in oNode.ChildNodes)
{
if (oNodeRequest.Name == "header")
{
foreach (XmlNode oNodeHeader in oNodeRequest.ChildNodes)
{
if (oNodeHeader.Name == "password")
oNodeHeader.InnerText = this.Password;
if (oNodeHeader.Name == "login")
oNodeHeader.InnerText = this.Username;
}
}
}
}
}
HttpWebRequest oWebRequest = null;
if (this.Test)
{
oWebRequest = (HttpWebRequest)WebRequest.Create(this.TestURL);
}
else
{
oWebRequest = (HttpWebRequest)WebRequest.Create(this.URL);
}
oWebRequest.CookieContainer = _cookies;
oWebRequest.Accept = "*/*";
oWebRequest.KeepAlive = true;
oWebRequest.UseDefaultCredentials = true;
oWebRequest.UserAgent = "Mozilla/5.0";
oWebRequest.PreAuthenticate = true;
oWebRequest.Credentials = new NetworkCredential(this.Username, this.Password);
oWebRequest.ContentType = "text/xml";
oWebRequest.Method = "POST";
byte[] bytes = Encoding.UTF8.GetBytes(xDocument.InnerXml.ToString());
oWebRequest.ContentLength = bytes.Length;
using (Stream oStream = oWebRequest.GetRequestStream())
{
oStream.Write(bytes, 0, bytes.Length);
}
using (WebResponse oWebResponse = oWebRequest.GetResponse())
{
if (oWebResponse == null)
return null;
using (StreamReader oStreamReader = new StreamReader(oWebResponse.GetResponseStream()))
{
return oStreamReader.ReadToEnd().Trim();
}
}
}
}
|
|
|
|
|
It might be worth finding a forum that specialises in meinpacket's dealer API, especially given it is in German.
My best guesses:
The username and password combination are wrong. Check these first as it is the simplest fix.
You pass the username and password in the XML body itself. This could be correct, but if I was writing the API I'd want security at the HTTP level so people couldn't just send any old guff to my service to see if they can hack it. I'd expect the HttpWebRequest.Credentials[^] property to be populated. If needed the credentials could be different to the XML ones, this is something you'd need to check with your provider. https://mp-api.mepa-home.de/dealerapi/[^] 403's suggesting it needs the extra creds, https://mp-api.mepa-home.de/dealerapi/xml[^] doesn't so it's anybody's guess.
|
|
|
|
|
It is the same, when I do not change anything inside the XMLDocument. And I populate the credentials in this line
oWebRequest.Credentials = new NetworkCredential(this.Username, this.Password);
The Problem is, I can't upload any request at all. So I think, this is an error I am doing. But I do not know what I am doing wrong here.
|
|
|
|
|
You may not even need that line. You really need to talk to the MeinPacket people, only they know what their security is.
Security (especially with a 3rd party) is normally a PITA, especially if they provide inadequate support and info.
|
|
|
|
|
Do you also have an example app or something that does work, so you can compare the network traffic?
|
|
|
|
|
How To implement the N number of thread in c#
|
|
|
|
|
There are many ways. Without knowing what you are really after here, I'll go with the obvious answer of a loop and the Thread[^] class.
|
|
|
|
|
using a loop can be the simplest and best(in my opinion)way to implement a given number of thread........... view this link for further details of loops if you donot know about loops http://msdn.microsoft.com/en-us/library/ch45axte.aspx[^]
also see some liknk for while loop and then use the one you prefer many other loops are also available..........
Best of luck........
Regards,
Ahsan Naveed
|
|
|
|
|
using a loop can be the simplest and best(in my opinion)way to implement a given number of thread........... view this link for further details of loops if you donot know about loops http://msdn.microsoft.com/en-us/library/ch45axte.aspx[^]
also see some likk for while loop and then use the one you prefer many other loops are also available..........
Best of luck........
Regards,
Ahsan Naveed
|
|
|
|
|
Ahsan98 wrote: using a loop can be the simplest and best(in my opinion)way to implement a given number of thread Loops and threads are two different concepts; they're not exchangeable.
A thread runs asynchronous to the code of the application-thread. It does not block processing.
A loop is a (blocking) repetition of a piece of code.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for injecting some protein into the pabulum being served
... edit ... I should have mentioned that what led me to Lippert's posts was this thread on StackOverFlow where multi-threading and looping is discussed:[^].
You might find Eric Lippert's warnings about the "breaking change" in C#5.0 in terms of 'foreach loop behavior interesting: [^], [^].
yours, Bill
~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal
modified 20-Aug-13 23:39pm.
|
|
|
|
|
|
Hey.
I made a website and a windows application which use one database. windows application duty is to register,editing,reporting data to database and website is just a static web application to show data!
well i need some council to decide how i share database between them!
Is better to keep database on a host and windows app connect it with IP server adress in connectionstring? or i should use webservie?
Which one is more safe?
Which one is more flexible?
Is there another way?
What if internet connection lost and windowss app is trying to register some data?(some data will be lost)
I decide to store data into a local database and a timer will update main database on the host every 10 minutes!Is it good? Is there better way?
(C#, ASP.NET,SQLSERVER)
thank you !
|
|
|
|
|
source.compiler wrote: Which one is more safe? The webservice might be better in identifying brute-force attempts.
source.compiler wrote: Which one is more flexible? A webservice, since it's custom code.
source.compiler wrote: Is there another way? Write your own server and protocol. Doesn't offer much additional benefits though.
source.compiler wrote: What if internet connection lost and windowss app is trying to register some data?(some data will be lost) It could be, depends on what you do with it.
source.compiler wrote: I decide to store data into a local database and a timer will update main database on the host every 10 minutes!Is it good? Is there better way? Ditch the timer. Simply write everything to the remote PC and a local copy/cache, and do a "merge" as soon as the user is online again.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: Ditch the timer. Simply write everything to the remote PC and a local copy/cache, and do a "merge" as soon as the user is online again.
If i store a copy of updated database into a dataset,then does not it use memory much?or it needs to have a local database on hard?
Thank you!
|
|
|
|
|
Web-service approach will be more safe, and flexible; so, I don't think you should think about any other option when there are web-services.
That is good thing that you are keeping such issues (like internet connection lost) in mind while working on your application.
A better way could be to do a proper exception handling while connecting to the web-service as well as while calling methods of the web-service. If you are not connected, or some of the method has not returned the expected results this means something wrong happened. In that case you should keep backup of that record only and try re-inserting that record into the database laters. This entirely depends upon how much critical is that data for you with respect to usage point of view. You can try it re-inserting every 10 minutes of may be once in a day. But don't forget to remove the backup of that record once it is inserted into live database (For backup, you can use the same copy of database locally)
|
|
|
|
|
Hi,
How can I implement rdlc report designer inside my application, the user could design their reports as the need and finally to save them as rdlc file format.
Best regards.
|
|
|
|
|
I'm new to C# and have been reading up on Classes. In my small app, I want to instantiate a class called 'backupJob'. There are two operationType members: local to remote server and syncing both ways. I want to create an object for one op type and then create another object for the other type.
In the demos I have seen they always show this:
Car myCar1 = new Car();
Car myCar2 = new Car();
I may end up with more than two backup jobs so I'm thinking there must be a better way to manage the object names besides myCar1 and myCar2, etc. I will want to delete an object as well as create more objects so is it best to keep track of these objects in an Array or possibly a Collection?
Thanks...
|
|
|
|
|
Create and maintain objects in a collection (list maybe). You can add and remove objects as required from within the list.
|
|
|
|
|
As Abhinav suggests, a collection is the easiest way to go: declare it as class level as a private List and you can do what you want with it:
private List<Car> myCars = new List<Car>();
...
Car car = new Car();
car.Color = blue;
car.Fuel = Fuels.Diesel;
myCars.Add(car);
...
myCars.Remove(car);
...
foreach (Car car in myCars)
{
car.Respray(Color.Red);
}
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
Thanks for the help...!!!
|
|
|
|
|
You're welcome!
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|