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
VulpesPosted Sep 6, 2013, 6:00 AM
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 albertPosted Sep 6, 2013, 6:16 AM
albert albertPosted Sep 6, 2013, 5:07 AM
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.
VulpesPosted Sep 5, 2013, 11:41 AM
albert albertPosted Sep 5, 2013, 9:45 AM
private string _connectionString = @"server=DEV12;database=acceptance_primavera_net2_r0713;uid=sa;pwd=Misoft;";
to this:
private string _connectionString = txtConfigurationName.Text;
albert albertPosted Sep 5, 2013, 9:41 AM
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 = "";
VulpesPosted Sep 5, 2013, 8:38 AM
_connectionString = txtConfigurationName.Text;
and then calling whatever method you call now to open the connection and load the database with the appropriate table.
albert albertPosted Sep 5, 2013, 8:03 AM
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;";
VulpesPosted Sep 5, 2013, 7:33 AM
txtConfigurationName.Text = nodeList.Item(listBox1.SelectedIndex).InnerText;
albert albertPosted Sep 5, 2013, 7:29 AM
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.
VulpesPosted Sep 5, 2013, 6:59 AM
albert albertPosted Sep 5, 2013, 6:56 AM
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.
VulpesPosted Sep 5, 2013, 6:43 AM
txtConfigurationName.Text = nodeList.Item(listBox1.SelectedIndex).Value;
albert albertPosted Sep 5, 2013, 6:09 AM
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
albert albertPosted Sep 5, 2013, 5:54 AM
foreach (XmlNode node in nodeList)
{
if (listBox1.SelectedIndex == 1)
txtConfigurationName.Text = listBox1.Items.Add(node.InnerText);
}
For testing.
But then I get this error: