Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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
Edited 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
0 OriginalGriff 210
1 Richard MacCutchan 100
2 kbrandwijk 100
3 ProgramFOX 80
4 Mukesh Bhagat 65
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2014
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