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
Guest User
Tech Writer
2
1.1k
display mysql database data in Tab control winforms c#
May 31 2019 8:59 PM
I have a mysql database linked to a tab control with multiple tables. I got the first table display in one tab page. But I cannot get the data to be displayed into another tab control. How do I do this? Also What is the code to perform the insert, update and delete the data?
using
System.Xml.Linq;
using
MySql;
using
System.Configuration;
using
MySql.Data;
using
System.Xml;
using
System.IO;
using
System.Runtime.InteropServices;
using
Telerik.WinControls;
using
Telerik.WinControls.UI;
using
Telerik.WinControls.UI.Docking;
using
System.Globalization;
namespace
mydatabase
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(object sender, EventArgs e)
{
this
.IsMdiContainer =
true
;
string constring =
"datasource=localhost;Port=3306;database=mydatabase;username=root;password=mypassword;persist security info=True"
;
MySqlConnection MySqlConn =
new
MySqlConnection(constring);
MySqlCommand command =
new
MySqlCommand(
"select * from mydatabase.Authors;"
, MySqlConn);
try
{
MySqlDataAdapter daAuthors =
new
MySqlDataAdapter();
daAuthors.SelectCommand = command;
DataTable dtAuthors =
new
DataTable();
DataSet dsAuthors =
new
DataSet();
daAuthors.Fill(dtAuthors);
dsAuthors.Tables.Add(dtAuthors);
dtAuthors.Columns[
"AuthorID"
].AutoIncrement =
true
;
dtAuthors.Columns[0].AutoIncrementStep = 1;
// Bind the DataTable to the UI via a BindingSource.
BindingSource AuthorBindingSource =
new
BindingSource();
AuthorBindingSource.DataSource = dtAuthors;
// binding source binding
AuthorBindingNavigator.BindingSource = AuthorBindingSource;
// Navigator Binding
txtAuthorID.DataBindings.Add(
"Text"
, AuthorBindingSource,
"AuthorID"
);
txtAuthorCode.DataBindings.Add(
"Text"
, AuthorBindingSource,
"AuthorCode"
);
txtAuthorName.DataBindings.Add(
"Text"
, AuthorBindingSource,
"AuthorName"
);
// if it didn't find the key, position = 1
// you can also try any else proper event
//AuthorBindingSource.Position = AuthorBindingSource.Find("AuthorID", Interaction.IIf(string.IsNullOrEmpty(txtAuthorID.Text), 0, txtAuthorID.Text));
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
string conBook =
"datasource=localhost;Port=3306;database=mydatabase;userid=root;password=mypassword;persist security info=True"
;
MySqlConnection mySqlConnBook =
new
MySqlConnection(conBook);
MySqlCommand cmdBook =
new
MySqlCommand(
"SELECT * From mydatabase.Book"
, mySqlConnBook);
MySqlDataAdapter daBook =
new
MySqlDataAdapter();
daBook.SelectCommand = cmdBook;
DataTable dtBook =
new
DataTable();
DataSet dsBook =
new
DataSet();
// daBook.MissingSchemaAction = MissingSchemaAction.AddWithKey;
daBook.Fill(dtBook);
dsBook.Tables.Add(dtBook);
// MySqlCommandBuilder cbBook = new MySqlCommandBuilder(daBook);
dtBook.Columns[
"BookCodeID"
].AutoIncrement =
true
;
dtBook.Columns[0].AutoIncrementStep = 1;
// Bind the DataTable to the UI via a BindingSource.
BindingSource BookBindingSource =
new
BindingSource();
BookBindingSource.DataSource = dtBook;
BookBindingNavigator.BindingSource = BookBindingSource;
txtBookCodeID.DataBindings.Add(
"Text"
, BookBindingSource,
"BookCodeID"
);
txtBookDescription.DataBindings.Add(
"Text"
, BookBindingSource,
"BookDescription"
);
}
}
private
void
next_radPageViewPage(RadPageViewPage radPageViewPage1, RadPageViewPage radPageViewPage2)
{
radPageView1.SelectedPage = radPageViewPage2;
radPageViewPage2.BindingContextChanged += (_, __) =>
radPageView1.SelectedPage = radPageViewPage1;
}
}
}
Reply
Answers (
1
)
Get Latest and Get Changeset
how to rename all files ina folder to incrmeenting numbers?