|
only two letters away from being an asset
|
|
|
|
|
Hello,
You can use your Windows Form to get connected to your Database. There are number of choices that you have to make regarding the database server and then you can get connected to the database and have the luxury of sending and receiving data between your Windows Application and the database, such as storing Passwords, checking the login information and etc.
I personaly use MySQL and it works just fine. Could you tell us what data base you are using so I can direct you to some Beginer's tutorial and get you started with simple commands to get you started?
I hope I could be a help.
Khoramdin
-- modified at 12:00 Tuesday 27th March, 2007
|
|
|
|
|
Tq sir,
I'm using mysql.How to connect to mysql using visual C#.How to compare the password. Can you help me sir.
Before this I have create a password form that I set default password in coding of button click.
I want to upgrade it so I can compare password and change password from the database.Tq sir
|
|
|
|
|
Hello mate,
Windows Applications were never meant to be connected to anythingelse than MS product. But you are in LUCK as there are ways to make your Windows Application work flawlessly with other technologies such as MySQL.
Step 1:
In order for your Windows Application written in C# to get connected to MySQL you need to have the right driver. You can get this from the good old MySQL website. Here is the link to save you the time and the headache looking for it, mate.
http://dev.mysql.com/downloads/connector/odbc/3.51.html[^]
Download and install the right package and then you are ready for Rock & Roll.
Step 2:
Add the following into your C# Windows Application:
private System.Data.Odbc.OdbcConnection OdbcCon;
private System.Data.Odbc.OdbcCommand OdbcCom;
private System.Data.Odbc.OdbcDataReader OdbcDR;
private System.Data.Odbc.OdbcDataAdapter OdbcAd;
private string ConStr;
Step 3:
Now you are ready to talk to your Database, mate. Just talk to your database using MySQL commands. What can be done is simply limited only by your imagination.
Here is a few examples to set you in the right direction.
Example 1: Getting Connected to MySQL database:
private void btnConnect_Click(object sender, EventArgs e)<br />
{<br />
ConStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" + txtIP.Text + ";PORT=" + txtPort.Text + ";DATABASE=" + txtDatabase.Text + ";UID=" + txtUsername.Text + ";PWD=" + txtPassword.Text + ";OPTION=3";<br />
OdbcCon = new System.Data.Odbc.OdbcConnection(ConStr);<br />
btnListTables.Enabled = true;<br />
<br />
try<br />
{<br />
txtLog.AppendText("Openning connection...\r\n");<br />
if (OdbcCon.State == ConnectionState.Closed)<br />
{<br />
OdbcCon.Open();<br />
}<br />
txtLog.AppendText("Connection opened\r\n");<br />
}<br />
catch (System.Data.Odbc.OdbcException Ex)<br />
{<br />
txtLog.AppendText(Ex.Message + "\r\n");<br />
MessageBox.Show("Could not access the database.\r\nPlease make sure you completed the fields with the correct information and try again.\r\n\r\nMore details:\r\n" + Ex.Message, "Database connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
}<br />
Example 2: Showing all the tables:
private void btnListTables_Click(object sender, EventArgs e)<br />
{<br />
if (OdbcCon.State == ConnectionState.Open)<br />
{<br />
OdbcCom = new System.Data.Odbc.OdbcCommand("SHOW TABLES", OdbcCon);<br />
OdbcDR = OdbcCom.ExecuteReader();<br />
txtLog.AppendText("Tables inside " + txtDatabase.Text + ":\r\n");<br />
while (OdbcDR.Read())<br />
{<br />
txtLog.AppendText(">> " + OdbcDR[0] + "\r\n");<br />
}<br />
}<br />
}
For some reason you are seeing the words PORT as ";PORT" and PWD as ";PWD" in the above code. Just replace the smily faces with the correct word and you should be alright. You need to place ";" before the word PORT and PWD. I guess ";" + "P" gives the smily face.
By the, my humble apology for the messy codes.
I hope this gets you started.
Khoramdin
-- modified at 12:49 Tuesday 27th March, 2007
|
|
|
|
|
Hi,
Imagine that i'm in photoshop for example. Once open, photoshop has a couple of toolbars and toolboxes.
When i create a new image or open an existent image it will open a new window, and that window, if resized will not get out of the main window.
How do i create such kind of window?
Thx,
Nuno
|
|
|
|
|
That is called an MDI application. There are lots of articles on how to create them.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
I'm trying to find out how I can connect the reportviewer to a Datatable I created through the program.
my code:
DataTable DataForReport = new DataTable("DataForReport");
DataColumn Number = new DataColumn(); // function number
Number.DataType = System.Type.GetType("System.String");
Number.ColumnName = "NUMBER";
DataForReport.Columns.Add(Number);
DataColumn Descriptor = new DataColumn(); // function caption
Descriptor.DataType = System.Type.GetType("System.String");
Descriptor.ColumnName = "DESCRIPTOR";
DataForReport.Columns.Add(Descriptor);
DataColumn Quantity = new DataColumn(); // quantity sold
Quantity.DataType = System.Type.GetType("System.Decimal");
Quantity.ColumnName = "QUANTITY";
Quantity.DefaultValue = 0;
DataForReport.Columns.Add(Quantity);
DataColumn Sales = new DataColumn(); // gross sales amount
Sales.DataType = System.Type.GetType("System.Decimal");
Sales.ColumnName = "SALES";
Sales.DefaultValue = 0;
DataForReport.Columns.Add(Sales);
DataColumn Discount = new DataColumn(); // discount amount
Discount.DataType = System.Type.GetType("System.Decimal");
Discount.ColumnName = "DISCOUNT";
Discount.DefaultValue = 0;
DataForReport.Columns.Add(Discount);
DataColumn Net = new DataColumn(); // net amount
Net.DataType = System.Type.GetType("System.Decimal");
Net.ColumnName = "NET";
Net.DefaultValue = 0;
DataForReport.Columns.Add(Net);
DataColumn Cost = new DataColumn(); // cost price
Cost.DataType = System.Type.GetType("System.Decimal");
Cost.ColumnName = "COST";
Cost.DefaultValue = 0;
DataForReport.Columns.Add(Cost);
DataColumn Margin = new DataColumn(); // net amount
Margin.DataType = System.Type.GetType("System.Decimal");
Margin.ColumnName = "MARGIN";
Margin.DefaultValue = 0;
DataForReport.Columns.Add(Margin);
//make number the primary key in the table
DataColumn[] DataForReportKey = new DataColumn[1];
DataForReportKey[0] = DataForReport.Columns["NUMBER"];
DataForReport.PrimaryKey = DataForReportKey;
DataRow row;
row = DataForReport.NewRow();
for (int cnt = 0; cnt <= foundRows.GetUpperBound(0); cnt++)
{
string number = Convert.ToString(foundRows[cnt].ItemArray[10]);
string caption = Convert.ToString(foundRows[cnt].ItemArray[9]);
Decimal quantity = Convert.ToDecimal(foundRows[cnt].ItemArray[11]);
Decimal sales = Convert.ToDecimal(foundRows[cnt].ItemArray[12]);
Decimal discount = Convert.ToDecimal(foundRows[cnt].ItemArray[21]);
Decimal net = sales-discount;
Decimal cost = Convert.ToDecimal(foundRows[cnt].ItemArray[20]);
Decimal margin = net - cost;
DataRow rowfind = DataForReport.Rows.Find(number);
//does the table already contain the same?
if (rowfind == null)
{
//if not then add the record to the table
DataForReport.Rows.Add(number, caption, quantity, sales, discount, net, cost,margin);
}
else
{
//if the record exists then add the sales counters and store the new values
Int32 index = Convert.ToInt32(number) - 1;
DataForReport.Rows[index]["quantity"]
= quantity + (Convert.ToDecimal(DataForReport.Rows[index].ItemArray[2]));
DataForReport.Rows[index]["sales"]
= sales + (Convert.ToDecimal(DataForReport.Rows[index].ItemArray[3]));
DataForReport.Rows[index]["discount"]
= discount + (Convert.ToDecimal(DataForReport.Rows[index].ItemArray[4]));
DataForReport.Rows[index]["net"]
= net + (Convert.ToDecimal(DataForReport.Rows[index].ItemArray[5]));
DataForReport.Rows[index]["cost"]
= cost + (Convert.ToDecimal(DataForReport.Rows[index].ItemArray[6]));
DataForReport.Rows[index]["margin"]
= margin + (Convert.ToDecimal(DataForReport.Rows[index].ItemArray[7]));
}
}
return DataForReport.Rows.Count; //return the number of records
now I want the reportviewer to display the data as stored in the datatable DataForReports. How can I accomplish that?
hope someone can help me out
rgds
Frank
|
|
|
|
|
System.IO.File class have many functions..like move(),copy(),delete() etc etc.
but there are no Rename function.How can i rename a file(may be Doc file).
|
|
|
|
|
Hello,
The System.IO.FileInfo class has the "MoveTo" method for this casses.
System.IO.FileInfo fi = new System.IO.FileInfo("oldName");
fi.MoveTo("newName");
All the best,
Martin
|
|
|
|
|
Short explanation of the situation:
In my Form (main) i have embbeded a datagrid and a usercontrol with a panel inside on which i paint the names (nodes) of the datagrid.
for example in a treeview it would look like this:
food
+-meat
+-bread
###+-corn
###+-wheat
food can be bread or meat. On the panel of the usercontrol i draw then the food, the meat and the bread. Then i draw two lines to connect the food with the meat and the bread. Now i want to click on the bread and a contextMenu shouldappear with Next. When i click next it should repaint the panel with
bread
+-corn
+-wheat
To do so i need to go back to the datagrid and select the bread there. I have allready a method which selects me the right cell when i give it the text which item should be selected (here the string: bread). But here is my problem.
How do i send a message form the usercontrol to the form.
I was thinking it should work somehow with an event.
But i don't know exactly how to do it or where to start.
(Something like observer pattern)
I make an event in the usercontrol.
And the Form should notice it when the event is executed.
i thought on something like this:
in usercontrol:
public event EventHandler next = null;
and in the form:
usercontrol.next +=new EventHandler(usercontrol_back)
and then the handler for it.
private void usercontrol_next(object sender, EventArgs e)
{
//the method i need to call
}
but how do I say in my usercontrol that the event should be fired or started?
How does my form notice that the event is fired in my usercontrol?
And how do i get the string from the usercontrol to my datagrid (in the form)?
|
|
|
|
|
|
I am working on a COM dll in C# that needs to pass an ADODB recordset back to
the calling VBScript. I believe I have everthing setup correctly, as the
calls work, and it looks like a recordset is returned, however, the recordset
is null or closed. What is the trick to passing a recordset back from C#?
The Call:
Set rs = CreateObject("Interface")
rs.Init "System", "ODBC", "user", "pass", "database", "server"
retVal = rs.DataImport("value")
C#:
using ADODB;
[Guid("C3C26A94-9639-43c4-B59C-E245C8A68D44")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface iInterface
{
[DispId(1)] bool DataExport(string OrderNumber, string
TrackingNumber, decimal Freight, decimal Weight, string ShipDate, string
ShipVia, string MiscNum);
[DispId(2)] bool DataVoid(string OrderNumber, string TrackingNumber,
decimal Freight, decimal Weight, string MiscNum);
[DispId(3)] Recordset DataImport(string OrderNumber);
[DispId(4)] void Init(string nameVal, string odbcVal, string
userVal, string passVal, string dbVal, string srvVal);
}
[Guid("EF8369F0-CF42-40b1-B3F3-0EC54CE73FF4")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Interface")]
public class PSIHeader:iInterface
{
public Recordset DataImport(string OrderNumber)
{
//misc stuff - create connection, query etc...
//Recordset creation and return
rs.CursorLocation = CursorLocationEnum.adUseClient;
rs.Open(query.ToString(), cn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic, -1);
return rs;
}
}
I have been using regasm to register the type library.
Thanks
|
|
|
|
|
hi, i need to know how i can exit from sub(method) in c#, i mean keywork like exit sub in vb.net
123
|
|
|
|
|
return;
But, it is better to have only one return statement and use conditionals to control what code is executed. Refactoring often helps.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
But I am so glad at least one other person in the world shares my philosophy about return statements.
File Not Found
|
|
|
|
|
i know this keyword(return) but this keyword use in function,i need like this keyword in method
example
public void f()
{
1: command (Execute
2: Command (Execute
exit sub (in vb.net) (what i can write here like this code in c#)
3: Command (not Execute
4: Command (Not Execute
}
123
|
|
|
|
|
Suppose we have two form. FormA and FormB. FormA has a button. i want when i click the button then Form2 would be open and at that time FormA should be Dispose. but how i dispose FormA?
button click event:
Form2 oForm2=new Form2();
oForm2.ShowDialog();
this.Dispose();
but this code could not dispose the FormA.
Pls help me on this.
|
|
|
|
|
Hello,
You have to use the Show Method instead of ShowDialog.
and then Close (will call the Dispose method also) the FormA.
Form2 oForm2=new Form2();
oForm2.Show();
this.Close();
Does not work if FormA is your main form. Because then your program will end and all forms will be closed.
All the best,
Martin
|
|
|
|
|
|
Instead, you should create both forms as control, and put them both on the one form, showing one at a time.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
sorry, i can't get your point.
|
|
|
|
|
Create two user controls. Design each to look like one of the forms you need. Put both on a form. Alternate which one is Visible to decide which 'form' is showing.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Guys,
consider following code:
byte [] bytes = new byte[160];
FillBytes(ref bytes);
System.Net.IPAddress ipaddress = new System.Net.IPAddress(1684300900);
System.Net.IPEndPoint ipendpoint = new System.Net.IPEndPoint(ipaddress, 7000);
udpclient = new UdpClient();
try{
int sent = 0;
sent = udpclient.Send(bytes, bytes.Length, SystemInformation.ComputerName, 7000);
MessageBox.Show(Encoding.ASCII.GetString(bytes));
lbl_bytessent.Text = "Sent: " + sent;
}
catch(Exception ex){
MessageBox.Show("send result: error: " + ex.Message);
}
PS: I left the comments to show what I've already tried
I need to send some bytes to a receiving application. I have a small example in VB6 where it seems to work, so I tried in C# to do the same. The bytes that are sent (is set in integer sent) is always correct, the function doesn't come in the catch. However, the receiving application does not seem to react, but it does so with the VB6 application. I'm guessing I need to set some relation between sender and receiver, but I can't figure out how.
Any help on this? According to the examples on MSDN, I'm quite correct?
Thanks !
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
hi,
i am having Form1,Form2,and Form3
In Form2 i am having some values like selecting a radioButton,check box,or entering some text in the textboxes.
then i will be moving to Form3..
Now how can i Save the content of Form2..
if i come back from Form3 to Form2 i should load my values..
Help me pls
With Regards
prasad
|
|
|
|
|
First, please tell me they are not called that...
The easiest way to do this is to make your forms controls within the one form, and change which one is visible. If Form2 disappears when Form3 shows, that's the best way to approach that, in general. The other way to do it, is to just hide Form2, instead of destroying it.
The controls approach is nicer.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|