Click here to Skip to main content
15,917,642 members
Home / Discussions / C#
   

C#

 
GeneralRe: Single Array Vs 2D Array to represent a Matrix... Pin
harold aptroot11-May-10 2:52
harold aptroot11-May-10 2:52 
GeneralRe: Single Array Vs 2D Array to represent a Matrix... Pin
Are Jay11-May-10 4:57
Are Jay11-May-10 4:57 
QuestionHow to work with IRC in C# Pin
adilabbasi10-May-10 14:25
adilabbasi10-May-10 14:25 
AnswerRe: How to work with IRC in C# Pin
Dr.Walt Fair, PE10-May-10 16:10
professionalDr.Walt Fair, PE10-May-10 16:10 
AnswerRe: How to work with IRC in C# Pin
Peace ON10-May-10 20:31
Peace ON10-May-10 20:31 
QuestionAssemblyInfo Pin
Ryan Minor10-May-10 14:09
Ryan Minor10-May-10 14:09 
AnswerRe: AssemblyInfo Pin
Abhinav S10-May-10 17:08
Abhinav S10-May-10 17:08 
QuestionCombobox with datasource doesn't sort correctly after adding a record [modified] Pin
rpfEYNMAN10-May-10 7:52
rpfEYNMAN10-May-10 7:52 
Hello,
I am a newbie here and have an issue with a combobox. When a requestor is added, a form using a showdialog method is opened and the user is asked to enter and confirm their email address. When this is completed, the user clicks a button which adds the new requestor beautifully. It even keep that requestor as the selected one in the combobox of the request form but it places this new record at the end of the list in the combobox. The datasource of this combo is a table in an access datatabase. Can anyone help? My code with the sections of issue is below.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Outlook = Microsoft.Office.Interop.Outlook;
using CSharp;
namespace WinSIRAD
{
public partial class frmSTDREQ : Form
{
public frmSTDREQ()
{
InitializeComponent();
}

private void frmSTDREQ_Load(object sender, EventArgs e)
{
XmlTextReader textreader2 = new XmlTextReader(Environment.CurrentDirectory.ToString() + "\\XMLFile1.xml");
textreader2.WhitespaceHandling = WhitespaceHandling.None;
while (textreader2.Read())
{
switch (textreader2.NodeType)
{
case XmlNodeType.Element:
while (textreader2.MoveToNextAttribute())
break;
OleDbConnection myconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;" + textreader2.Value.ToString());
try
{
myconnection.Open();
}
catch
{
MessageBox.Show("Can Not Connect To The SIRAD Database!");
Application.Exit();
}
string sCmdString4 = "SELECT fldemailname,fldemailadd FROM tblAddBook ORDER BY fldemailname";
OleDbDataAdapter myadapter4 = new OleDbDataAdapter(sCmdString4, @"Provider=Microsoft.Jet.OLEDB.4.0;" + textreader2.Value.ToString());
DataTable myDT2 = new DataTable();
myadapter4.Fill(myDT2);
cboRequestor.DataSource = myDT2;
cboRequestor.DisplayMember = "fldemailname";
cboRequestor.ValueMember = "fldemailadd";
cboRequestor.SelectedIndex = -1;
myconnection.Close();
break;
}
}
}
}


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.Xml;
using System.Data.OleDb;



namespace WinSIRAD
{
public partial class frmNReq : Form
{
public frmNReq()
{
InitializeComponent();
}

private void btn1NReq_Click(object sender, EventArgs e)
{
if (txtBox2.Text != "" && txtBox1.Text != "")
{
if (txtBox1.Text != txtBox2.Text)
{
MessageBox.Show("The Email Addresses Do Not Match!", "Error", MessageBoxButtons.OK);
}
else
{
XmlTextReader textreader = new XmlTextReader(Environment.CurrentDirectory.ToString() + "\\XMLFile1.xml");
textreader.WhitespaceHandling = WhitespaceHandling.None;
while (textreader.Read())
{
switch (textreader.NodeType)
{
case XmlNodeType.Element:
while (textreader.MoveToNextAttribute())
break;
//Connect to the backend via XML string
OleDbConnection myconnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;" + textreader.Value.ToString());
try
{
myconnection.Open();
}
catch
{
//If connection cannot be made then warn user and exit SIRAD
MessageBox.Show("Can Not Connect To The SIRAD Database!");
Application.Exit();
}
string sCmdString3 = "SELECT fldemailname,fldemailadd FROM tbladdbook ORDER BY fldemailname";
OleDbDataAdapter myadapter3 = new OleDbDataAdapter(sCmdString3, @"Provider=Microsoft.Jet.OLEDB.4.0;" + textreader.Value.ToString());
OleDbCommandBuilder mycb = new OleDbCommandBuilder(myadapter3);
DataTable mydt = new DataTable();
myadapter3.Fill(mydt);
DataRow dnewrow = mydt.NewRow();
dnewrow["fldemailname"] = htxtbox.Text;
dnewrow["fldemailadd"] = txtBox1.Text;
mydt.Rows.Add(dnewrow);
myadapter3.Update(mydt);
MessageBox.Show("Entry Added");
Form frm = (Form)Application.OpenForms["frmSTDREQ"];
ComboBox cb = (ComboBox)frm.Controls["cboRequestor"];
cb.Datasource = null;
cb.items.Clear();
cb.DataSource = mydt;
cb.DisplayMember = "fldemailname";
cb.ValueMember = "fldemailadd"
cb.Text = htxtbox.Text;
myconnection.Close();
this.Close();
break;
}
}
}
}

modified on Monday, May 10, 2010 1:58 PM

AnswerRe: Combobox with datasource doesn't sort correctly after adding a record Pin
William Winner10-May-10 8:27
William Winner10-May-10 8:27 
GeneralRe: Combobox with datasource doesn't sort correctly after adding a record Pin
rpfEYNMAN10-May-10 10:00
rpfEYNMAN10-May-10 10:00 
QuestionDataGridView <-> PropertyGrid data binding Pin
rbuchana10-May-10 7:46
rbuchana10-May-10 7:46 
Questionsave a TreeView in database [modified] Pin
reza assar10-May-10 5:59
reza assar10-May-10 5:59 
AnswerRe: save a TreeView in database Pin
Michel Godfroid10-May-10 6:32
Michel Godfroid10-May-10 6:32 
AnswerRe: save a TreeView in database Pin
Pete O'Hanlon10-May-10 9:28
mvePete O'Hanlon10-May-10 9:28 
AnswerRe: save a TreeView in database Pin
Alex Manolescu10-May-10 10:31
Alex Manolescu10-May-10 10:31 
Questionsum calculated with the formula crystal report Pin
koncuk10-May-10 5:32
koncuk10-May-10 5:32 
QuestionWhat is the alternative to memcpy in C#? Pin
Abdulaziz M Zaben10-May-10 4:17
Abdulaziz M Zaben10-May-10 4:17 
AnswerRe: What is the alternative to memcpy in C#? Pin
Matt U.10-May-10 4:41
Matt U.10-May-10 4:41 
AnswerRe: What is the alternative to memcpy in C#? Pin
Peace ON10-May-10 4:41
Peace ON10-May-10 4:41 
AnswerRe: What is the alternative to memcpy in C#? Pin
Abdulaziz M Zaben10-May-10 4:56
Abdulaziz M Zaben10-May-10 4:56 
QuestionHow to work on Mobile Banking(SMS Banking)? Pin
CoderForEver10-May-10 2:40
CoderForEver10-May-10 2:40 
AnswerRe: How to work on Mobile Banking(SMS Banking)? Pin
Michel Godfroid10-May-10 3:59
Michel Godfroid10-May-10 3:59 
AnswerRe: How to work on Mobile Banking(SMS Banking)? Pin
CoderForEver10-May-10 4:18
CoderForEver10-May-10 4:18 
GeneralRe: How to work on Mobile Banking(SMS Banking)? Pin
Michel Godfroid10-May-10 5:10
Michel Godfroid10-May-10 5:10 
GeneralRe: How to work on Mobile Banking(SMS Banking)? Pin
CoderForEver10-May-10 7:24
CoderForEver10-May-10 7:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.