TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Emad Ahmed
NA
62
3k
Connect C# WinForms project to MySql through another WinFrom
Apr 21 2016 5:22 AM
I know my question have asked many times, but this time I want to do something more.
Simply, I make C# WinForms database using Telerik Winforms.
The scenario is like this:
1. I made a login form called (frmLogin) that includes a button
(btnDbConfig);
2. When I click (btnDbConfig) it open another form (frmConfig);
3. "frmConfig" will contain manually all the data for
connecting the application to MySql Database. The "frmConfig"
contains textboxes and buttons:
- Server textbox (txtServer)
- Port textbox (txtPort)
- Database textbox (txtDatabase)
- Database user textbox (TxtDbUser)
- Database password textbox (txtDbPassword)
- Save configuration button (btnSaveConfig)
- Cancel Button (txtDbCancel) `This.Close();` "frmConfig" will be connected to "MyCon.mdf" database and store the data entered by the
application user to be connected later to MySql database.
What I want is:
1. A C# code that inserts the data being entered in the textboxes in "frmConfig" into the "MyCom.mdf" when I Click "btnSaveConfig" button".
2. Another C# code to connect to MySql from textboxes in "frmConfig" through "frmLogin"'s login button "btnLogin".
3. The connection to MySql is to be applied to all the forms in the project.
Note : I work on Visual Studio 2015 and installed MySQl Connector.
Thank you for you help.
I adjusted this code to connect but not working:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace
MyCom
{
public
partial
class
frmConfig : Form
{
public
frmConfig()
{
InitializeComponent();
}
private
void
btnDbCancel_Click(
object
sender, EventArgs e)
{
this
.Close();
}
private
void
btnSaveConfig_Click(
object
sender, EventArgs e)
{
string
connetionString =
null
;
iCom.MySqlConnection cnn;
connetionString =
"server="
+ txtServer.Text +
";database="
+ txtDatabase.Text +
";Port=3306;uid="
+ txtDbUser.Text +
";pwd= "
+ txtDbPassword.Text +
";"
;
cnn =
new
MyCom.MySqlConnection(connetionString);
try
{
cnn.Open();
MessageBox.Show(
"Connection Open ! "
);
cnn.Close();
}
catch
(Exception ex)
{
MessageBox.Show(
"Can not open connection ! "
);
}
}
}
}
Reply
Answers (
5
)
State Saving with individual column filtering
how to datagridview filter in every day