Hi Everybody,
I have a Listbox and a textfield and then if you select from the listbox(ConnectionName) an item then in the textbox the connectionstring has to be shown.
I have this:
[code]
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
XmlDocument docHallo = new XmlDocument();
docHallo.Load(@"C:/Users/IllesIuliu/Documents/Visual Studio 2010/Projects/WindowsFormsApplication18/GetSelectedID/XML/Configurations.xml");
XmlNodeList nodeList = docHallo.GetElementsByTagName("SupplyXMLConnectionString");
//XmlNodeList nodelistConnectionString = docHallo.GetElementsByTagName()
txtConfigurationName.Text = nodeList.Item(listBox1.SelectedIndex).ToString();
}
[/code]
But then I get this as output:
System.Xml.XmlElement - in the textbox
THX
Loading

VulpesRank #55 · 29.2K reputationPosted Sep 6, 2013, 2:00 AM EDT
Try this:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// _connectionString = txtConnectionString.Text; // move this lower down
string selected = (string)listBox1.SelectedItem;
XmlDocument docHallo = new XmlDocument();
docHallo.Load(@"C:/Users/IllesIuliu/Documents/Visual Studio 2010/Projects/WindowsFormsApplication18/GetSelectedID/XML/Configurations.xml");
XmlNodeList nodeList = docHallo.GetElementsByTagName("SupplyXMLConnectionString");
txtConnectionString.Text = nodeList.Item(listBox1.SelectedIndex).InnerText;
_connectionString = txtConnectionString.Text;
hallo();
}
albert albertRank #2,683 · 519 reputationPosted Sep 5, 2013, 1:54 AM EDT
foreach (XmlNode node in nodeList)
{
if (listBox1.SelectedIndex == 1)
txtConfigurationName.Text = listBox1.Items.Add(node.InnerText);
}
For testing.
But then I get this error:
albert albertRank #2,683 · 519 reputationPosted Sep 5, 2013, 2:09 AM EDT
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
XmlDocument docHallo = new XmlDocument();
docHallo.Load(@"C:/Users/IllesIuliu/Documents/Visual Studio 2010/Projects/WindowsFormsApplication18/GetSelectedID/XML/Configurations.xml");
XmlNodeList nodeList = docHallo.GetElementsByTagName("SupplyXMLConnectionString");
// if (listBox1.SelectedIndex == 1)
txtConfigurationName.Text = nodeList.ToString(); // listBox1.SelectedItem(node.InnerText).ToString();
}
Then I see in the textbox:
System.Xml.XmlElementList
VulpesRank #55 · 29.2K reputationPosted Sep 5, 2013, 2:43 AM EDT
txtConfigurationName.Text = nodeList.Item(listBox1.SelectedIndex).Value;
albert albertRank #2,683 · 519 reputationPosted Sep 5, 2013, 2:56 AM EDT
for your replay.
I have it now like this:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = (string)listBox1.SelectedItem;
XmlDocument docHallo = new XmlDocument();
docHallo.Load(@"C:/Users/IllesIuliu/Documents/Visual Studio 2010/Projects/WindowsFormsApplication18/GetSelectedID/XML/Configurations.xml");
XmlNodeList nodeList = docHallo.GetElementsByTagName("SupplyXMLConnectionString");
txtConfigurationName.Text = nodeList.Item(listBox1.SelectedIndex).Value;
}
but I dont see anything in the textbox when I select a item from the dropdownlist.
VulpesRank #55 · 29.2K reputationPosted Sep 5, 2013, 2:59 AM EDT
albert albertRank #2,683 · 519 reputationPosted Sep 5, 2013, 3:29 AM EDT
here is the xml:
and so I have a listbox with the Name and then you can select the name in the listbox and then the associated SupplyXMLConnectionString will be shown in the TextBox.
VulpesRank #55 · 29.2K reputationPosted Sep 5, 2013, 3:33 AM EDT
txtConfigurationName.Text = nodeList.Item(listBox1.SelectedIndex).InnerText;
albert albertRank #2,683 · 519 reputationPosted Sep 5, 2013, 4:03 AM EDT
THX. It works now. But can you help me with other tread. That if you select and connectionstring that the database will automatically be loaded with a specific table - in this case: TripElement. Because I have it now hard coded, like this:
private string _connectionString = @"server=DEV12;database=prod_CycleTours_net2_backup_201107110300;uid=sa;pwd=misoft;";
VulpesRank #55 · 29.2K reputationPosted Sep 5, 2013, 4:38 AM EDT
_connectionString = txtConfigurationName.Text;
and then calling whatever method you call now to open the connection and load the database with the appropriate table.
albert albertRank #2,683 · 519 reputationPosted Sep 5, 2013, 5:41 AM EDT
I am using LINQ, like this:
public void hallo()
{
DataClasses1DataContext context = new DataClasses1DataContext(_connectionString);
var ok = from t in context.TripElements
where SqlMethods.Like(t.TripElementName, "%" + t.TripElementName.Contains(textBox1.Text.Trim())
)
select new
{
TripElementID = t.TripElementID,
SegmentTypeCode = t.SegmentTypeCode,
TripElementCode = t.TripElementCode,
tripElementName = t.TripElementName
};
dataGridView1.DataSource = ok;
textBox1.Text = "";
albert albertRank #2,683 · 519 reputationPosted Sep 5, 2013, 5:45 AM EDT
private string _connectionString = @"server=DEV12;database=acceptance_primavera_net2_r0713;uid=sa;pwd=Misoft;";
to this:
private string _connectionString = txtConfigurationName.Text;
VulpesRank #55 · 29.2K reputationPosted Sep 5, 2013, 7:41 AM EDT
albert albertRank #2,683 · 519 reputationPosted Sep 6, 2013, 1:07 AM EDT
I have it now like this:
This is my search query:
public void rep_bind()
{
DataClasses1DataContext context = new DataClasses1DataContext(_connectionString);
//_connectionString = txtConnectionString.Text;
var selectTrip = (from t in context.TripElements
where (t.TripElementCode == textBox1.Text.Trim() || t.SegmentTypeCode == textBox1 .Text.Trim()
)
select new
{
TripElementID = t.TripElementID,
SegmentTypeCode = t.SegmentTypeCode,
TripElementCode = t.TripElementCode,
tripElementName = t.TripElementName
}).ToList();
dataGridView1.DataSource = selectTrip;
textBox1.Text = "";
}
and this is listbox with all the connectionstrings:
[code]
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
_connectionString = txtConnectionString.Text;
string selected = (string)listBox1.SelectedItem;
XmlDocument docHallo = new XmlDocument();
docHallo.Load(@"C:/Users/IllesIuliu/Documents/Visual Studio 2010/Projects/WindowsFormsApplication18/GetSelectedID/XML/Configurations.xml");
XmlNodeList nodeList = docHallo.GetElementsByTagName("SupplyXMLConnectionString");
txtConnectionString.Text = nodeList.Item(listBox1.SelectedIndex).InnerText;
}
[/code]
and this is for my connectionstring:
private string loadConnectionString;
private string _connectionString;// = @"server=DEV12;database=prod_CycleTours_net2_backup_201107110300;uid=sa;pwd=misoft;";
But so If I remove the hardcoded connectionstring then I get this error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
But if I do it hardcoded then it works.
albert albertRank #2,683 · 519 reputationPosted Sep 6, 2013, 2:16 AM EDT