|
I am working on a program in C# the program is like a personal database holds numbers, names, little bit of everything even have a section for calculating and managing my bills. I have pretty much everything done, majority of the code and have the MySql DB finished. The problem I have is I want the information I have in the DB to be pulled and placed in txt boxes. I can pull the info and put it in a DataGrid but that is not what I am wanting to do. I am just having a hard time trying to figure out how to get the DB information to be pulled into the text boxes that I have. I did have this similar program using XML, but I want to take it a step further.
|
|
|
|
|
ok i think i have it now, just need to make some minor alterations, and instead of using a load button i will be using a the Select.Item.Index from a listbox to retrieve the information from the database. if anyone has any comments or notices room for correction please let me know. i enjoy C# but i am new to the combination of C# & MySql.
private void loadBtn_Click(object sender, EventArgs e)<br />
{<br />
string strFindMovie = "SELECT movie_name FROM movie WHERE movie_id='1'";<br />
<br />
MySql.Data.MySqlClient.MySqlConnection conDatabase = new <br />
MySql.Data.MySqlClient.MySqlConnection("Data Source=localhost; Database=moviesite; username=******; password=*****");<br />
MySql.Data.MySqlClient.MySqlCommand cmdDatabase = new <br />
MySql.Data.MySqlClient.MySqlCommand(strFindMovie, conDatabase);<br />
<br />
conDatabase.Open();<br />
<br />
MySql.Data.MySqlClient.MySqlDataReader rdrMovie;<br />
rdrMovie = cmdDatabase.ExecuteReader();<br />
<br />
while (rdrMovie.Read())<br />
{<br />
this.nameTB.Text = rdrMovie.GetString(0);<br />
}<br />
<br />
rdrMovie.Close();<br />
conDatabase.Close();<br />
}
modified on Saturday, December 29, 2007 5:46:14 PM
|
|
|
|
|
shadowhazard wrote:
ok i think i have it now, just need to make some minor alterations, and instead of using a load button i will be using a the Select.Item.Index from a listbox to retrieve the information from the database. if anyone has any comments or notices room for correction please let me know. i enjoy C# but i am new to the combination of C# & MySql.
That sounds like the right thing to do. It's good to see that you solved the problem yourself. Way to go
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Yeah, was stumped at first on how to get it started then it hit me like a ton of brickes and then it fell into place. i use MySql for many things with web development now will be using it for the many database type programs i will be creating.
|
|
|
|
|
It's quite useful to use the try-finally and/or using blocks to ensure that connections etc are closed when some unforseen error occurs in your data handling code.
|
|
|
|
|
yeah, here is my updated version as of yesterday, again this code is just my sample code i am testing, this is not the DB and such that i will be using in my main program.
string strMovieName = this.movieNameTB.Text;<br />
<br />
try<br />
{<br />
<br />
if (strMovieName == "")<br />
{<br />
MessageBox.Show("You must provide the Movie name");<br />
return;<br />
}<br />
<br />
string strFindMovie = "SELECT * FROM movie WHERE movie_name = '" + strMovieName + "'";<br />
<br />
<br />
MySql.Data.MySqlClient.MySqlConnection conDatabase = new<br />
MySql.Data.MySqlClient.MySqlConnection("Data Source=localhost; Database=moviesite; Persist Security Info=yes; username=*******; password=*****");<br />
<br />
MySql.Data.MySqlClient.MySqlCommand cmdDatabase = new<br />
MySql.Data.MySqlClient.MySqlCommand(strFindMovie, conDatabase);<br />
<br />
conDatabase.Open();<br />
<br />
MySql.Data.MySqlClient.MySqlDataReader rdrMovie;<br />
rdrMovie = cmdDatabase.ExecuteReader();<br />
<br />
while (rdrMovie.Read())<br />
{<br />
this.typeTB.Text = rdrMovie.GetString(2);<br />
this.movieYearTB.Text = rdrMovie.GetString(3);<br />
}<br />
<br />
rdrMovie.Close();<br />
conDatabase.Close();<br />
}<br />
catch (MySqlException ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}
|
|
|
|
|
Hi friends,
I have a homework, i worked for hours but I got stuck in a point. I can't go out of this point.
I am very glad if you can help me.
I make effort to get a query from from northwind database sample. I want max sales of employees according to product.
There are 9 employees(sales persons). There are 77 products type. Salespersons sell this products. I want ,which product was sold maximumly according to sales turnover. The result must be like below
salesperson product sales amount
salesperson1 product a x
salesperson2 product b y
. .
. . .
.
salesperson9 product h w.
I tryed below script, I can find max sales of each salespersons but I can't add productname column to this query.
select t.firstname,t.lastname,max(t.sales) as sales
from (select employees.Firstname,employees.lastname,products.productname,
sum("order details".unitprice*quantity*(1-discount)) as Sales from ((Employees inner join orders on employees.employeeID=orders.employeeID) inner join "order details" on orders.orderID="order details".orderID) inner join products on products.productID="order details".productID
group by employees.lastname,employees.firstname,products.productname
) as t
group by t.firstname,t.lastname
order by t.firstname
Good DAys
Regards
|
|
|
|
|
Are you still having trouble?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Yes, I still can't find solution.
|
|
|
|
|
Don't you need a products.productname in the group by ?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
I need product name of max sold products in result table.
|
|
|
|
|
I want to build a very dynamic program but the thing is i need your help. I am reading the entire xml file on application startup. I want to display my custom Label when user click on the Next button, if user click again i want to display the the custom circle and so on.
Firstly, I don't want to load all the controls when application startsup. I want to separate controls from their data that way i wouldn't be loading those controls which aren't being displayed currently.
Secondly, offcourse any change in the data value should reflect the controls means if X value changes on the dataside so the controls X position value on the screen should changes as well.
Lastly, a very intersting thing i want to implement is that lets say a custom lable control is displayed and changes its position onMouseMove on the stage it should update it's class raw data.
Thanks for ur help
xml
Label
Text Hello World Text
width 10 width
height 15 height
Label
Circle
width 12 width
height 13 cheight
circle
Triangle
width 15 cwidth
height 20 width
Triangle
xml
|
|
|
|
|
hi,
for(i=0;i<4;i++)<br />
{<br />
if(i==0){button.Color=Color.Red;}<br />
else if(i==1){button.Color=Color.Blue;}<br />
else if(i==2){button.Color=Color.Black;}}<br />
else if(i==3){button.Color=Color.Yellow;}}<br />
}
why button color is not change?i want change the button color according to the if-else conditions.
I AM WORKING ON "PLOTTER ROBOT"(FYP).
|
|
|
|
|
Each color change causes a message that will be send to the button so that it will change it's color. The messages are queued and are all executed when you return the control to the message pump (when you exit the method).
You can use the DoEvents method to make the message pump handle the messages, and a delay so that you have time to actually see the change:
foreach (Color c in new Color[] { Color.Red, Color.Blue, Color.Black, Color.Yellow}) {
button.Color = c;
DoEvents();
Thread.Sleep(500);
}
However, if you really want to do something like this, you should use a timer instead.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
That'll just make your button yellow every time. Get rid of the for statement.
|
|
|
|
|
I have a file of 400 products. I can't import a file into the destination database but instead I have to go through a web page and manually input all the products one at a time. I was hoping to speed this up by writing a program that would work similar to Google's browser auto-fill plugin so I could read from an exported file from our current database. Does anyone know how I can get a handle on the current browser window so that I can use the DOM and populate specific fields? Thanks.
|
|
|
|
|
You would need to use P/Invoke interop calls to some of the Win32 API calls. I'm not sure which ones off-hand.
There is a potentially easier way, which would be to make use of the HttWebRequest object and the HTML parser[^] found in this article.
You would need code similar to this:
HttpWebRequest webRequest = WebRequest.Create("http://www.codeproject.com") as HttpWebRequest;
string html = "";
if (webRequest != null)
{
HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse;
if (response != null)
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
html = reader.ReadToEnd();
}
}
}
if (html.Length > 0)
{
HtmlParser parser = new HtmlParser();
HtmlNodeCollection nodes = parser.Parse(html);
HtmlNodeCollection tables = nodes.FindByName("table");
HtmlNode table = tables[6];
} As you can see, you can access the HTML in a similar method as you would XML, or you can load it directly into an XmlDocument (once you have selected a single HtmlNode element by using the following:
XmlDocument xml = new XmlDocument();
xml.LoadXml(table.XHTML);
XmlNodeList tableRows = xml.SelectNodes("//tr");
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Hi
Here is the scenario of exception handling for my applications:
I have a translator that translate exceptions to a meaningful message for user.
When an unhandled exception occurs there is an Application ThreadException handler that is supposed to catch and handle the exception(To translate it using the translator and show a message box to user)
When I compile my solution and run the exe file everything goes fine but when I'm in debug mode it doesn't work and if there's an unhandled exception the debugger stops and shows me the exception.
What should I do to use my Exception handling scenario even while I'm debugging?
Thanx
|
|
|
|
|
Hi,
I susggest you have a look at the menu Debug/Exceptions...
|
|
|
|
|
Hi guys. i have two Questions to make sure the serialization of objects does not alter the following concepts:
i may use windows application with either mdb or MS SQL database.
Is it possible to those database files such as micrsoft access or microsoft SQL to convert binary format, like BIN files extension?
OR with those database files above can be converted in to dll files?
thanks so much for helping..
so much of happy ending...
|
|
|
|
|
zafax4 wrote: i may use windows application with either mdb or MS SQL database.
Yes.
zafax4 wrote: Is it possible to [missing verb] those database files such as micrsoft access or microsoft SQL to convert binary format, like BIN files extension?
I don't understand the question.
zafax4 wrote: OR with those database files above can be converted in to dll files?
I don't see how converting a database to a DLL would be helpful in anyway. A DLL file is fairly static. It generally does not change. In fact, while the program is running it cannot change as the operating system locks the file. By contrast, database files tend to change all the time.
|
|
|
|
|
I don't think any of your questions actually impact object serialization in any way.
You can use a Windows application with any database technology you want. Typically the actual database files are in a proprietary format specific to the database engine (technology) and aren't human-readable. If you want to prevent someone from opening the database outside of your application (through a database management tool) then you need to use the database security mechanisms to password protect your database.
DLLs are not used for data like this. If you want to "embed" the database in to your application, you should look at Microsoft SQL Server Compact Edition[^]
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Thanks you so much scott its really helpful and im happy that u helped me.
i need to database to be embeded in the application as you said, but i dont want to do security externally by using password.
thanks lot!
so much of happy ending...
|
|
|
|
|
You're welcome. The best option would probably be SQL Server CE (Compact Edition). It has a very small runtime footprint (2 DLLs) and stores the entire databse in a single file. It is very compatible with the full-blown SQL Server and pretty easy to work with.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Thanks Scott lot!
Just now im in the website u given , i'll go through this more and found some helpful samples too!.
scott i really appreciate you being so helpful. thanks .
so much of happy ending...
|
|
|
|