So this is a noobish question but I'm failing to get the correct results.
I have a table (
Data Table 1) in a DB that I have successfully connected to and extracted to a DataSet. Now I used the MSDN-website provided example code to test the information, and the code (
Code Snippet 1) prints out every piece of data flawlessly by going trough every row and and every column on the row and adding them to a string, (used only for testing purposes).
What I want is for a set of variables to be "edited" which is used in a function (
Code Snippet 2) to ultimately add a new XAML element, which at some point will be a dynamic starmap.
I basically want to have a loop which populates a canvas with ellipses based on the information in the database's table's rows.
The code below is messy as hell, and just plain stupid in some places but It works, giving me a message box with the DB-table's contents in one long string. The data-table below is just for reference and are only a few columns of a whole lot.
thanks for any and all help!
Code snippet 1:
private void TestDBconnection()
{
string connetionString = null;
OleDbConnection DbConn;
connetionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Frank R. Haugen\Documents\Visual Studio 2010\Projects\StarApp\WpfApplication1\10_closest_stars.accdb;";
DbConn = new OleDbConnection(connetionString);
string SqlQueryString = "SELECT * FROM [10 closest stars]";
DbConn.Open();
DataSet myDataSet = new DataSet();
OleDbConnection objConnection = new OleDbConnection(connetionString);
OleDbCommand objCommand = new OleDbCommand(SqlQueryString, objConnection);
objConnection.Open();
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(objCommand);
myDataAdapter.Fill(myDataSet, "[10 closest stars]");
string Response = "";
foreach (DataTable table in myDataSet.Tables)
{
foreach (DataRow row in table.Rows)
{
foreach (DataColumn column in table.Columns)
{
Response += row[column] + ";";
}
}
}
MessageBox.Show(Response);
objConnection.Close();
DbConn.Close();
}
Data Table 1:
ID HYG GLIESE SERV
32263 32349 Gl 244 A
53879 54035 Gl 411 NULL
70667 70890 Gl 551 NULL
71454 71681 Gl 559 B
71457 71683 Gl 559 A
87666 87937 Gl 699 NULL
92116 92403 Gl 729 NULL
118081 0 Gl 65 B
Code Snippet 2:
var tool = new StackPanel();
tool.Children.Add(new TextBlock() { Text = "Proxima Centauri" });
tool.Children.Add(new TextBlock() { Text = "-1,538676906;-1,178494413;-3,752088504" });
var star = new Ellipse
{
Height = 5,
Width = 5,
Fill = Brushes.Blue,
RenderTransform = new TranslateTransform(-2, -2),
ToolTip = tool,
Cursor = Cursors.Hand
};
star.SetValue(Canvas.LeftProperty, 60.0);
star.SetValue(Canvas.TopProperty, 20.0);
star.SetValue(Canvas.ZIndexProperty, -500);
starfield.Children.Add(star);
This code is not yet been made compatible with the above so it has absolute values instead of referring to variables.