У меня есть база данных mysql, связанная с элементом управления вкладками с несколькими таблицами в Visual Studio. Данные об авторах загрузятся в первую форму tabcontrol. Однако возникла проблема, из-за которой я не могу отобразить данные Книги в другой форме управления вкладками.
using System.Xml.Linq;
using MySql;
using System.Configuration;
using MySql.Data;
using System.Xml;
using System.IO;
using System.Runtime.InteropServices;
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 ="atasource=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; AuthorBindingNavigator.BindingSource = AuthorBindingSource;
txtAuthorID.DataBindings.Add("Text", AuthorBindingSource, "AuthorID");
txtAuthorCode.DataBindings.Add("Text", AuthorBindingSource, "AuthorCode");
txtAuthorName.DataBindings.Add("Text", AuthorBindingSource, "AuthorName");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.GetType().ToString());
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();
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");
}
}
}
}
Любая помощь будет принята с благодарностью