8 Replies - 2324 Views - Last Post: 06 March 2010 - 12:59 PM Rate Topic: -----

#1 plot911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-March 10

save (.mdb) file wihtout using savedialog browser

Posted 06 March 2010 - 10:04 AM

Help me with my dilemma on how to save (.mdb) file wihtout using savedialog browser.. i know how to save into text file but i searched the internet about saving a database file (.mdb) to a path but none fits my requirement..

thanks..i'm sorry for frequently asking questions it's just that i am new to C# and SQL..

Thanks for all the help..
Is This A Good Question/Topic? 0
  • +

Replies To: save (.mdb) file wihtout using savedialog browser

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: save (.mdb) file wihtout using savedialog browser

Posted 06 March 2010 - 10:57 AM

so what exactly is your problem? You can't just write some data to a file and make it a .mdb file and expect it to work. Database files are different from text files.
Was This Post Helpful? 0
  • +
  • -

#3 plot911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-March 10

Re: save (.mdb) file wihtout using savedialog browser

Posted 06 March 2010 - 11:13 AM

my program creates .mdb file and needs to be saved but it uses savefiledialog..how am i suppose to code it in such a way that it will not use savefiledialog but automatically save to specified path??
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: save (.mdb) file wihtout using savedialog browser

Posted 06 March 2010 - 11:54 AM

It makes a MDF file? You're going to need to show how it's created so we can show you how to save it (as it can more than likely be done in the same method)
Was This Post Helpful? 0
  • +
  • -

#5 plot911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-March 10

Re: save (.mdb) file wihtout using savedialog browser

Posted 06 March 2010 - 12:12 PM

creating a new .mdb file and saving it without using save file dialog

 private void btnNew_Click(object sender, EventArgs e)
        {
            Catalog weightDatabase = new Catalog();
            Table databaseTable;
            // close any open database
            CloseConnection();
            try
            {
                // get filename
                if (dlgSave.ShowDialog() == DialogResult.OK)
                {
                    weightDatabase.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " + dlgSave.FileName);
                    // create table
                    databaseTable = new Table();
                    databaseTable.Name = "Weight";
                    // add fields
                    databaseTable.Columns.Append("TherapyDate", DataTypeEnum.adDate, 20);
                    databaseTable.Columns.Append("AverageX", DataTypeEnum.adSingle, 10);
                    databaseTable.Columns.Append("AverageY", DataTypeEnum.adSingle, 10);
                    databaseTable.Columns.Append("AverageZ", DataTypeEnum.adWChar, 50);
                    databaseTable.Columns.Append("MaximumX", DataTypeEnum.adSingle, 10);
                    databaseTable.Columns.Append("MaximumY", DataTypeEnum.adSingle, 10);
                    databaseTable.Columns.Append("MaximumZ", DataTypeEnum.adWChar, 50);
                    databaseTable.Columns["AverageX"].Attributes = ColumnAttributesEnum.adColNullable;
                    databaseTable.Columns["AverageY"].Attributes = ColumnAttributesEnum.adColNullable;
                    databaseTable.Columns["AverageZ"].Attributes = ColumnAttributesEnum.adColNullable;
                    databaseTable.Columns["MaximumX"].Attributes = ColumnAttributesEnum.adColNullable;
                    databaseTable.Columns["MaximumY"].Attributes = ColumnAttributesEnum.adColNullable;
                    databaseTable.Columns["MaximumZ"].Attributes = ColumnAttributesEnum.adColNullable;
                    // primary key
                    databaseTable.Keys.Append("PK_Weight", KeyTypeEnum.adKeyPrimary, "TherapyDate", null, null);
                    databaseTable.Indexes.Append("TherapyDate", "TherapyDate");
                    weightDatabase.Tables.Append(databaseTable);
                    // connect to database
                    //OpenConnection(dlgSave.FileName);
                    // fill dates
                    DateTime tableDate = new DateTime(Convert.ToInt32(cboYear.Text), 1, 1);
                    DateTime nextYear = new DateTime(Convert.ToInt32(cboYear.Text) + 1, 1, 1);
                    int nDays = (nextYear - tableDate).Days;
                    DataRow newRow;
                    for (int n = 1; n <= nDays; n++)
                    {
                        newRow = weightTable.NewRow();
                        newRow["TherapyDate"] = tableDate;
                        weightTable.Rows.Add(newRow);
                        tableDate += new TimeSpan(1, 0, 0, 0);
                    }
                    grdWeight_CellClick(null, null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Creating Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                weightDatabase = null;
            }
        }


Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#6 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: save (.mdb) file wihtout using savedialog browser

Posted 06 March 2010 - 12:29 PM

Is "Catalog" a custom class? I am having a hard time finding it on the MSDN.
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: save (.mdb) file wihtout using savedialog browser

Posted 06 March 2010 - 12:30 PM

It has to be because it's not found anywhere
Was This Post Helpful? 0
  • +
  • -

#8 plot911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-March 10

Re: save (.mdb) file wihtout using savedialog browser

Posted 06 March 2010 - 12:34 PM

it's a class but i don't know what type...

@Psycho: what do u mean?/can i possibly do that saving without opening a savefiledialog browser??
Was This Post Helpful? 0
  • +
  • -

#9 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: save (.mdb) file wihtout using savedialog browser

Posted 06 March 2010 - 12:59 PM

View Postplot911, on 06 March 2010 - 02:34 PM, said:

it's a class but i don't know what type...

@Psycho: what do u mean?/can i possibly do that saving without opening a savefiledialog browser??


Yes, you can save files without the SaveFileDialog. The SaveFileDialog is simply there to give you the directory where the user wants to save it. If you already know where you want to save it, you don't need to show it. It's NOT required to save a file.

You are going to have to find out more about the "Catalog" class since it must be custom to your application. We don't know what it does, therefore, we can't tell you how to save it.

Is it a third-party class? Do you have the source code for it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1