|
Brothers,
I've successfully coded to load data from db (sql server) to combobox in c sharp (ex: productname); but when I add new data to db (from c sharp), I want to add an pID of productname instead of the productname to db because I have two tables in db which have relationship together (ex: pID, productname) and (ex: cID, pID, qty, price).
Lastly, I have another form to add more productname to db; so, how to refresh the combobox (as mentioned above) when this form is closed?
Thanks so much
Chuon Visoth
Angkor Wat - Cambodia
asp.net - c sharp beginner
|
|
|
|
|
Hi Chuon Visoth
A Combobox as 2 properties Display Member & Value member. Assign "productname" as your Display member & "pID" as your value member. while saving data to your table assign value member.
The "pID" & "productname" both columns should be in the query from which you assign it to commandText & then get Datatable
Ex:- combobox1.DisplayMember = "productname"
comboBox1.ValueMember = "pID"
Thanks & Regards
Satish Pai B
|
|
|
|
|
But this wouldn't refresh it, he would also have to update the DataTable that the combobox is bound to.
|
|
|
|
|
Thanks for your support.
I've found the way to load pID and productname; but my second question I've not found it yet.
How to do that? HELP ... !
Chuon Visoth
Angkor Wat - Cambodia
asp.net - c sharp beginner
|
|
|
|
|
|
Hi,
I am writing a program that needs to manipulate Animation Master's models(an 3d animation program).
Hash Inc have available an sdk for developing plug ins using C++. But they have an ActiveX that exposes all the sdk libruary, it's called WebHAMR.
I really need to do what I need to do fast, and because of this I am using C# Express 2008.
I really don't want to do it in C++
This is what I do:
I add WebHAMR as a Reference, And it works fine if I just place a WebHAMR control on a form and load a 3d model.
The problem I am having is that if I create an object using the library exposed by WebHAMR, I get the following error:
Retrieving the COM class factory for component with CLSID {2FDB515C-EA6A-4B4A-8300-A0446FEB7F78} failed due to the following error: 80040154.
I really need help, I am limited on time.
Thanks
|
|
|
|
|
I have a localized form set up with default, en-CA and fr-CA languages. I tried testing the form, for each of the languages by changing the HKCU\Software\Policies\Microsoft\Control Panel\Desktop\MultiUILanguageID value between 0409 (en-US), 1009 (en-CA) and 0C0C (fr-CA). The correct localized text is displayed everytime I test the form without debugging but not when I test using VS debugger.
Here's what I do:
1. Create a localized form with a button which closes the form.
2. Update HKCU\Software\Policies\Microsoft\Control Panel\Desktop\MultiUILanguageID value to 0C0C (was originally 0409)
3. From Visual Studio IDE window, choose "Start without Debugging"
4. Form displays with French text as expected
5. Update HKCU\Software\Policies\Microsoft\Control Panel\Desktop\MultiUILanguageID value to 1009
6. From Visual Studio IDE window, choose "Start without Debugging"
7. Form now displays with Canadian English text - again, as expected
8. Update HKCU\Software\Policies\Microsoft\Control Panel\Desktop\MultiUILanguageID value back to 0C0C
9. From Visual Studio IDE window, choose "Start Debugging"
10. Form displays with Canadian English text - expected to be French
11. Repeat step 9 above - without touching the registry value (still 0C0C)
12. Form now displays in French as expected
I noticed that if I want the form to display in the correct language, in debug mode, I need to run it twice after changing the registry value.
I test by changing HKCU\Software\Policies\Microsoft\Control Panel\Desktop\MultiUILanguageID value because I don't want to change locale in Control Panel everytime. Is this test valid? If so, does anyone know why my test results are different between "Debug" and 'non-Debug"?
Thank you.
cpl
|
|
|
|
|
Hello
I am trying to update record in a database. I can see the changes in the datagrid, but they don't get saved into the database.. The 3 textboxes show the values of the currently selected row in the datagrid. So i press the Change button to make the textboxes active, change the text and then click the Save button.
Here's how the form looks like: http://img529.imageshack.us/my.php?image=45903634.jpg
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private SqlConnection conn;
private string connStr;
SqlDataAdapter da;
DataSet ds;
bool b;
public Form1()
{
InitializeComponent();
connStr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\\dbOne.mdf" + ";Integrated Security=True;Connect Timeout=30;User Instance=True";
conn = new SqlConnection(connStr);
conn.Open();
string selectStr = "select * from people";
da = new SqlDataAdapter(selectStr, conn);
ds=new DataSet();
da.Fill(ds,"people");
da.InsertCommand = new SqlCommand("insert into people(name, age) values (@name, @age)", conn);
da.InsertCommand.Parameters.Add("@name",SqlDbType.VarChar,50,"name");
da.InsertCommand.Parameters.Add("@age",SqlDbType.Int,5,"age");
da.UpdateCommand = new SqlCommand("update people set name=@name, age=@age where id=@id",conn);
da.UpdateCommand.Parameters.Add("@name",SqlDbType.VarChar,50,"name");
da.UpdateCommand.Parameters.Add("@age",SqlDbType.Int,5,"age");
da.UpdateCommand.Parameters.Add("@id",SqlDbType.Int,5,"id");
da.DeleteCommand = new SqlCommand("delete from people where id=@id",conn);
da.DeleteCommand.Parameters.Add("@id",SqlDbType.Int,5,"id");
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.DataSource = ds.Tables["people"];
txtId.DataBindings.Add("Text",ds.Tables["people"],"id");
txtName.DataBindings.Add("Text", ds.Tables["people"], "name");
txtAge.DataBindings.Add("Text", ds.Tables["people"], "age");
txtId.Enabled = false; txtName.Enabled = false; txtAge.Enabled = false;
btnSave.Enabled = false; btnCancel.Enabled = false;
conn.Close();
}
private void btnChange_Click(object sender, EventArgs e)
{
b = false;
txtName.Enabled = true; txtAge.Enabled = true;
btnNew.Enabled = false; btnDelete.Enabled = false; btnSave.Enabled = true; btnCancel.Enabled = true;
}
private void btnSave_Click(object sender, EventArgs e)
{
if (b)
{
DataRow newLine = ds.Tables["people"].NewRow();
newLine["name"] = txtName.Text;
newLine["age"] = txtAge.Text;
ds.Tables["people"].Rows.Add(newLine);
}
da.Update(ds,"people");
}
private void btnNew_Click(object sender, EventArgs e)
{
b = true;
int i = ds.Tables["people"].Rows.Count;
dataGridView1.Rows[i].Selected = true;
txtId.Text = ""; txtName.Text = ""; txtAge.Text = "";
txtName.Enabled = true; txtAge.Enabled = true;
btnSave.Enabled = true; btnCancel.Enabled = true;
}
private void btnDelete_Click(object sender, EventArgs e)
{
int i = int.Parse(dataGridView1.CurrentRow.Index.ToString());
ds.Tables["people"].Rows[i].Delete();
da.Update(ds,"people");
}
}
}
|
|
|
|
|
Your Code is very Ugly, you are not even trapping exceptions, and you open connections at wrong places.
This is how you update a Datagrid
[^]
Hope it Helps
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Everytime i multiselect files it creates so many tabs as files selected..but there is only text of first file in first tab..other tabs are empty...
Here i have code for opening file:
private void evtOpenFile_Click(object sender, EventArgs e)
{
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
foreach (String file in openFileDialog1.FileNames)
{
evtNewDocument_Click(sender, e);
RichTextBox richTextBox1 = new RichTextBox();
richTextBox1 = tabControl1.SelectedTab.Controls[0] as RichTextBox;
richTextBox1.LoadFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText);
saveFileDialog1.FileName = openFileDialog1.FileName;
FileInfo fi = new FileInfo(openFileDialog1.FileName);
string pot = fi.Name;
tabControl1.SelectedTab.Text = pot;
pot = "";
}
}
}
evtNewDocument_Click(sender, e); creates new tab in tabcontrol with selectedindex on it! Still can't figure out what is wrong... PLZ HELP!
THanks
|
|
|
|
|
Aljaz111 wrote: richTextBox1 = tabControl1.SelectedTab.Controls[0] as RichTextBox;
for each iteration of the foreach this statement acts exactly the same, AFAIK SelectedTab is not changing (unless there is something hidden inside evtNewDocument_Click that succeeds in changing the tab whilst inside the evtOpenFile_Click, so the GUI thread is busy and not acting on extra messages right now).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
TabPage newPage = new TabPage();
newPage.Text = "Nov"+tabControl1.TabPages.Count;
tabControl1.TabPages.Add(newPage);
tabControl1.SelectedIndex = i;
i++
I am changing selectedindex..Something is wrong with changing to next text file.. In all tabs richtextboxes is text from first file in multiselect..
modified on Wednesday, May 27, 2009 8:13 PM
|
|
|
|
|
Sorry, I missed that.
There is one mistake though, you foreach "file" but never use it, instead you use "openFileDialog1.FileName" all the time, which isn't right. That would make all textboxes show the same text.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
Aljaz111 wrote: What should i change??
the only thing that changes value for each iteration of the foreach is the "file" variable, so you should USE it where ever you need to do something to one of the many files you are handling one by one.
If the code inside the foreach block does not rely on "file" it will perform the same actions over and over again, always using the same data.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
So where to use file?...Or can i walk through files in some other way?
|
|
|
|
|
Hint: what do you think openFileDialog1.FileName is holding when multiple files are selected?
Suggestion: buy a tutorial book on C# and work your way through it, you will acquire a lot of knowledge and insight from it.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I got it..thanks for letting me think;)
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi.
Could you guide me what the equal of this struct is in C# ?
struct chromo_typ
{
string bits;
float fitness;
chromo_typ(): bits(""), fitness(0.0f){};
chromo_typ(string bts, float ftns): bits(bts), fitness(ftns){}
};
Thanks
|
|
|
|
|
I must be getting really rusty with my C++ (It has been about 8 years) that I don't even know what some of this means any more:
chromo_typ(): bits(""), fitness(0.0f){};
chromo_typ(string bts, float ftns): bits(bts), fitness(ftns){}
What does the code after the colons do?
Man who stand on hill with mouth open wait long time for roast duck to drop in
|
|
|
|
|
Colin Angus Mackay wrote: What does the code after the colons do?
this struct has been used like this :
chromo_typ temp[POP_SIZE];
temp[cPop++] = chromo_typ(offspring1, 0.0f);
temp[cPop++] = chromo_typ(offspring2, 0.0f);
|
|
|
|
|
This demonstraits potential usage. It doesn't explain what the code after the colons on each line do. However, jimmanuel's explanation of how to convert your code to C# explains it.
Man who stand on hill with mouth open wait long time for roast duck to drop in
|
|
|
|
|
public class chromo_typ
{
public string bits { get; set; }
public float fitness { get; set; }
public chromo_typ() { bits = ""; fitness = 0.0f; }
public chromo_typ(string bts, float ftns) { bits = bts; fitness = ftns; }
}
I do believe this is right.
|
|
|
|
|
the float and string member variables are straightforward and the struct should be a class in C# (unless you have good reason to use a struct). The tricky stuff comes after that.
This
chromo_typ(): bits(""), fitness(0.0f){}; is a constructor with minimal code formatting, here's an expanded version that's a bit easier on the eyes:
chromo_typ() :
bits(""),
fitness(0.0f)
{
}; That's a parameterless constructor with an initialization list (you can google that for more info). A very similar way of writing that constructor would be this:
chromo_typ()
{
bits = "";
fitness = "0.0f;
}; Now, in C++ there are subtles difference between those two versions of the function but for the purposes of the C++ -> C# conversion you needn't worry about them. This version of the function is another pretty straightforward conversion from one language to the other.
The second chromo_typ(...) line is just another constructor with some parameters. You should be able to convert that one the same way as the first
|
|
|
|
|