|
Relative directorys, put your DB in your application folder and then use System.Windows.Forms.Application.ExecutablePath and it will point to the db.
|
|
|
|
|
EliottA wrote: put your DB in your application folder
NOOOOOOOOOOOOOOOOO!
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Not even if it's Access?
|
|
|
|
|
Hi Greeg, what do you recommend?
|
|
|
|
|
The easiest way I have found to deploy a database is to embed it in the assembly and then on first start check the application data directory for the file. If it doesn't exist write it using GetType().Assembly.GetManifestResourceStream("theEmbeddedName") which returns a stream that I save to a file.
The application data path is
System.Windows.Forms.Application.CommonAppDataPath
embed a file in an assembly is as easy as adding it the project and selecting Build Action:Embedded Resource.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
I suppose that partly depends on what database system is in use and what sort of environment it runs in. And whether or not other such databases are present.
In a corporate environment with "real" databases (i.e. not Access) there will likely be administrators to tell you where to stick it.
For home use you can pretty much do as you please, but try not to put it on a system ( C: ) drive.
modified on Saturday, January 24, 2009 12:50 AM
|
|
|
|
|
You can try to connect to your database, and if failed, open a connection dialog with this
If you are using an access datatable, it can be adapted for use an oledb connection.
Alex
|
|
|
|
|
Good afternoon.
I would like to create a Multi Column (2)ComboBox populated by existing (SQL) dataset.
The dataset returns the record ID and the item name (e.g. 1, "Apple"). The comboBox would display the item name, and the record ID would be hidden, but still "tied" to the item name.
Also I would like to reference the 1st colums to be used in another SQL statement.
I noticed a couple of examples (some with DataGrids), but they don't seem to suit our needs.
Thank you,
WHEELS
|
|
|
|
|
If you're returning two values but only want one displayed then you don't need a multi column combobox. You can use the standard one and set the DisplayMember and ValueMember properties to acheive exactly what you describe.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi DaveyM69.
I am very new to C#. More of a VBA master. I took C many moons ago, but am struggling a bit in C#.
I am vaugely familiar with the properties you mentioned, but how do I do what you suggest?
WHEELS
|
|
|
|
|
Assuming you're returning a DataSet from the database, set the ComboBox's DataSource to the Table you need in the DataSet. Set the ComboBox's DisplayMember to the column that has the text in that Table and the ValueMember to the column that has the ID.
That's all there is to it!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thank you Dave.
I beleive that should do the trick.
WHEELS
|
|
|
|
|
Hi Dave.
I have the following code:
ds = d.GeneralDropDown("Dept");
foreach (DataRow dr in ds.Tables[0].Rows)
{
//cboDeptID.Items.Add(dr[constrDeptID].ToString());
//cboDepartment.Items.Add(dr[constrDeptID].ToString() + " " + dr[constrDeptColumn].ToString());
cboDepartment.Items.Add(dr[constrDeptColumn].ToString());
cboDepartment.DisplayMember = dr[constrDeptColumn].ToString();
cboDepartment.ValueMember = dr[constrDeptID].ToString();
}
private void cboDeptID_SelectedIndexChanged(object sender, EventArgs e)
{
//ds = new DataSet();
//ds = d.FillDataGrid(this.cboDepartment,this.cboAcronym);
MessageBox.Show(this.cboDepartment.ValueMember);
MessageBox.Show(this.cboDepartment.DisplayMember);
}
Am I using the DisplayMemeber and ValueMember correctly? The combobox is poppulated, but the MessageBoxes don't come up when the value in the combobox changes.
Any ideas? WHEELS
|
|
|
|
|
There's no need to add your items in a loop, just assign the combo's DataSource to the DataSet's DataTable (ds.Tables[0]) and set the DisplayMember and ValueMember to the table's respective ColumnNames and that should fill the combo.
To get the value just get the combobox's SelectedValue. Working example below
void InitializeCombo()
{
DataSet ds = new DataSet();
ds.Tables.Add();
ds.Tables[0].Columns.Add("ID");
ds.Tables[0].Columns.Add("Display");
ds.Tables[0].Rows.Add(new object[] { 1, "One" });
ds.Tables[0].Rows.Add(new object[] { 2, "Two" });
ds.Tables[0].Rows.Add(new object[] { 3, "Three" });
ds.Tables[0].Rows.Add(new object[] { 4, "Four" });
ds.Tables[0].Rows.Add(new object[] { 5, "Five" });
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "Display";
comboBox1.ValueMember = "ID";
comboBox1.SelectedIndexChanged += new EventHandler(
comboBox1_SelectedIndexChanged);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.SelectedValue.ToString());
}
P.S. There's no need for all the x.ToString()s that you have everywhere!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thank you Dave.
I greatly appreciate you help.
WHEELS
|
|
|
|
|
No problem, that's what's these forums and all the users are here for
Any more problems, just post back.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Did you get it working OK?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi Dave.
I am on a differwnt project, but we experiment with the code using the dataset from the DAL layer next Wednesday.
Have a great weekend,
DAVE
|
|
|
|
|
Hi Dave.
Finding it challenging to get it working.
I have a form with a comboBox and the following code:
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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
const string constrLetterColumn = "Letter";
const string constrDeptID = "DeptID";
const string constrDeptColumn = "Department";
const string constrExpandColumn = "Expansion";
DAL d = new DAL();
DataSet ds;
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
void InitializeCombo()
{
// Constructing data set in code, obviously this would come from your DAL
DataSet ds = new DataSet();
ds.Tables.Add();
ds.Tables[0].Columns.Add("ID");
ds.Tables[0].Columns.Add("Display");
ds.Tables[0].Rows.Add(new object[] { 1, "One" });
ds.Tables[0].Rows.Add(new object[] { 2, "Two" });
ds.Tables[0].Rows.Add(new object[] { 3, "Three" });
ds.Tables[0].Rows.Add(new object[] { 4, "Four" });
ds.Tables[0].Rows.Add(new object[] { 5, "Five" });
// the next three lines fill your combo and set the members
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "Display";
comboBox1.ValueMember = "ID";
// subscribe to SelectedIndexChanged event
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.SelectedValue.ToString());
}
}
}
Where am I going wrong?
WHEELS
|
|
|
|
|
HI Dave.
I had a coworker work with me on the code.
It works well.
When I cut and pasted some code from another project, it didn't work because I was missing an event handler.
Thank you,
DAVE
|
|
|
|
|
Cool - glad to help
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hello all, sometimes the easiest things are the things you oversee the most.
I have an application, it's generally finished so-to speak. Now all that's left is just general cosmetics. My question lies herein; I have a splash screen. I want to put a progress bar on it to keep the user occupied while initialization and connections are established. My question is, how would I upgrade the progress bar so it actually reflects true progress of loading? This includes downloading tables from MySQL DB (and establishing a connection), loading RSS feeds etc.
How would you go about it, AFAIK there isn't a callback to determine how much data from a table has been loaded or how many feeds out of x have been downloaded.
Direction?
|
|
|
|
|
I think that's why progress bars never seem to progress evenly but jump around.
Easy solution is to set the style to Marquee then you're just indicating that it's doing something... but not how much.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Additionally to what Dave said, you might split up the loading process into steps like:
- 10% Initializing GUI
- 40% Loading DB
- 30% Downloading feeds
- 20% Calculating some stuff
Of course this will not be accurate, but there's not much you can do against it, it too much depends on the internet/DB connection and lots of other stuff.
If your DB driver supports it, then you can at least find out how many rows have already been fetched.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
This is my 1st time doing a C# assignment for my sch, and i need some string matching function...
Why am I getting this error and how do I solve it?
re.cs(2,19): error CS0234: The type or namespace name 'RegularExpressions' does
not exist in the namespace 'System.Text' (are you missing an assembly
reference?)
Thanks...
[Updated: I actually alr added "using System.Text.RegularExpressions; using System;", tt's why I am puzzled y cannot]
modified on Friday, January 23, 2009 2:44 PM
|
|
|
|