Click here to Skip to main content
12,943,528 members (49,885 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
This is what I have so far.
The following function is to fill the data table.
public void FillDT()
        {
            OleDbConnectionStringBuilder sb;
            sb = new OleDbConnectionStringBuilder();
            sb.Provider = "Provider=Microsoft.Jet.OLEDB.4.0;";
            sb.PersistSecurityInfo = false;
            sb.Add("Jet OLEDB:Database Password", "123456");
            SaveFileDialog sfd = new SaveFileDialog();
            if ((sb == null || sb.DataSource != null) && (sfd.FileName != null))
            {
                sb = new OleDbConnectionStringBuilder();
                sb.DataSource = sfd.FileName;
                return;
            }
 

            bookConn = new OleDbConnection(sb.Provider + "@Data Source=" + sb.DataSource + ";" + sb.PersistSecurityInfo);
            bookConn.Open();
            oleDbCmd.Connection = bookConn;
 
            oleDbCmd.CommandText = "INSERT INTO students (Firstname,Lastname,Age,Gender,School,Gfirstname,Glastname,Contact,Occupation,PostalAddr) Values('" + this.FirstnameTB.Text + "','" + this.LastnameTB.Text + "','" + this.AgeTB.Text + "','" + this.GenderTB.Text + "','" + this.SchoolTB.Text + "','" + this.GFirstnameTB.Text + "','" + this.GLastnameTB.Text + "','" + this.ContactTB.Text + "','" + this.OccupationTB.Text + "','" + this.AddressTB.Text + "');";
            int temp = oleDbCmd.ExecuteNonQuery();
 
            if (temp > 0)
            {
                FirstnameTB.Text = null;
                LastnameTB.Text = null;
                AgeTB.Text = null;
                GenderTB.Text = null;
                SchoolTB.Text = null;
                GFirstnameTB.Text = null;
                GLastnameTB.Text = null;
                ContactTB.Text = null;
                OccupationTB.Text = null;
                AddressTB.Text = null;
                MessageBox.Show("Record Successfuly Added", "Entry Added");
            }
            else
            {
                MessageBox.Show("Failed to Add Record", "Entry failure");
            }
            bookConn.Close();
            
        }


Please give me another solution to this.

The function fails to fill the data table the MessageBox.Show("Record Successfully Added"); does not even execute.

Thank you.
Posted 8-Jan-13 8:49am
Updated 8-Jan-13 9:39am
v4

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You don't show your savefiledialog, and if you did, you would return when it had run. I don't see what you want to do here, but, it's clear this is half written. Have you stepped through it in a debugger ?
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,643
CHill60 2,970
Maciej Los 2,348
Jochen Arndt 1,900
ppolymorphe 1,765


Advertise | Privacy | Mobile
Web01 | 2.8.170518.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100