Hi Guys I need some urgent help
I have Created a C# windows application to implement a form with
• a ListBox,
• a TextBox,
• an Edit button,
• an Insert button,
• a Delete button,
• a Update button and
• an Exit button.
[
I have also Created a database which interects with the window application. The BookCSharp DB should contain at least to 10 books about C# from 6 different authors. Information about these books should be arranged into the following two tables:
• Books – BookKey (that is ISBN), Title, Pages, AuthorKey, Publisher
• Authors – AuthorKey, First_Name, Surname
which I have done

Now the problem is here I have been able to connect the database to the windows application I have debugged it, and had the form appear also been able to have the exit button work but I have a problem on going about with the other buttons please can some one help me as I am a c# amateur .:'(

below is the code that I have executed so far

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 System.Data.OleDb;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
        
        }

        public static OleDbDataAdapter CreateDataAdapter(
          OleDbConnection connection)
        {

            string dbconnection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\mystery\Desktop\BookCSharp.accdb";
            string dbcommand = "Select Title Pages from Books;";
            OleDbDataAdapter adapter = new OleDbDataAdapter(dbcommand, dbconnection);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            DataTable dt = ds.Tables[0];
            foreach (DataRow row in dt.Rows)

            {
                listBox1.Items.Add(row["Title"] + "(" + row["Pages"] + ")");
            }
        }

        private void textbox1_Click_1(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void textbox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}

Recommended Answers

All 2 Replies

For a start I'm knot sure how you are going to insert into the database table with only one text box - I'm assuming you need to be able to add an author and book to the database.
You already have a database connection done so the only thing left is looking into how to UPDATE, INSERT and DELETE in a database.
I'm not going to provide you with code (it sounds a lot like a uni assignment to me) but for the insertion for example, you need to connect to the database and then add the data you want to insert into your SQL query:
INSERT INTO table_name VALUES(value1, value2, value3, etc)

Then execute the command and you should be done. You will find plenty of tutorials that explain ado.net and SQL online. Once you have had a crack at it and got some actual code to post up we can give more specific advice.

Thank you for the help Hericles. I think I am now in the right direction I am going to look at some ado.net and SQL tutorials as you suggested and then see where I go from there but thanks for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.