This is my first C# project and I'm building an application to track books I've read and want to read. Here's the code in my datahandling class. I am getting a Debug error on Application.Run that says "Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead. Is this error truly about that line of the code or about my class?
using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;
namespace BooksAuthors{ static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } }}
ClassDataHandling.cs:using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.SqlClient;
namespace BooksAuthors{ internal class ClassDataHandling { //BooksAuthors.ClassDataHandling _sqlData;
public void MainDataClass() { //specify SQL connection string string connString = @"Server=RHOADESD;Integrated Security=True;" + "Database=BOOKS"; SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter booksAdapter = new SqlDataAdapter( "Select * from books", conn); SqlDataAdapter bkauthlinkAdapter = new SqlDataAdapter( "Select * from bkauthlink", conn); SqlDataAdapter authorAdapter = new SqlDataAdapter( "Select * from authors", conn);
conn.Open();
//Create DataSet to contain related data tables, rows and columns DataSet BookAuthDataSet = new DataSet("BookAuthors"); booksAdapter.Fill(BookAuthDataSet, "books"); bkauthlinkAdapter.Fill(BookAuthDataSet, "bkauthlink"); authorAdapter.Fill(BookAuthDataSet, "authors");
conn.Close();
DataRelation book = BookAuthDataSet.Relations.Add( "BookRel", BookAuthDataSet.Tables["books"].Columns["booksID"], BookAuthDataSet.Tables["bkauthlink"].Columns["booksID"]); DataRelation author = BookAuthDataSet.Relations.Add( "AuthRel", BookAuthDataSet.Tables["authors"].Columns["authorsID"], BookAuthDataSet.Tables["bkauthlink"].Columns["authorsID"]);