Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Data Fetching and system.windows.forms.form & .datagridview

Reply
 
Old 11-10-2006   #1 (permalink)
fixitchris


 
 

Data Fetching and system.windows.forms.form & .datagridview

what's wrong with this code??? the form shows but the control is not binding.

help.

$da = New-Object system.data.sqlclient.sqldataadapter
$tbl = New-Object system.data.dataset
$cn2 = new-object system.data.SqlClient.SQLConnection("Data
Source=tcp:library;integrated Security=SSPI;Initial Catalog=cbprogram");
$cmd = new-object system.data.sqlclient.sqlcommand("select * from cblog",
$cn2);
$cn2.Open();
if ($cmd.ExecuteNonQuery() -ne -1)
{
echo "Failed";
}
$da.fill($tbl,"test");
'$cmd.ExecuteScalar() ;
[reflection.assembly]::loadwithpartialname("system.windows.forms");
$window = New-Object windows.forms.form;
$grid = New-Object windows.forms.datagridview;
$grid.DataSource = $tbl.tables("test");
$window.Controls.Add($grid);
'$grid.DataBindings();
$window.ShowDialog();

My System SpecsSystem Spec
Old 11-11-2006   #2 (permalink)
/\\/\\o\\/\\/ [MVP]


 
 

Re: Data Fetching and system.windows.forms.form & .datagridview

you need to use the baseobject to add the datasource,
e.g.

$DG.DataSource = $DT.psObject.baseobject

see also my datgrid GUI example here :

http://mow001.blogspot.com/2006/05/p...pdate-and.html

greetings /\/\o\/\/

"fixitchris" <fixitchris@discussions.microsoft.com> wrote in message
news:26D871ED-8130-45E5-A26F-E427CCBBA40E@microsoft.com...
> what's wrong with this code??? the form shows but the control is not
> binding.
>
> help.
>
> $da = New-Object system.data.sqlclient.sqldataadapter
> $tbl = New-Object system.data.dataset
> $cn2 = new-object system.data.SqlClient.SQLConnection("Data
> Source=tcp:library;integrated Security=SSPI;Initial Catalog=cbprogram");
> $cmd = new-object system.data.sqlclient.sqlcommand("select * from cblog",
> $cn2);
> $cn2.Open();
> if ($cmd.ExecuteNonQuery() -ne -1)
> {
> echo "Failed";
> }
> $da.fill($tbl,"test");
> '$cmd.ExecuteScalar() ;
> [reflection.assembly]::loadwithpartialname("system.windows.forms");
> $window = New-Object windows.forms.form;
> $grid = New-Object windows.forms.datagridview;
> $grid.DataSource = $tbl.tables("test");
> $window.Controls.Add($grid);
> '$grid.DataBindings();
> $window.ShowDialog();



My System SpecsSystem Spec
Old 11-13-2006   #3 (permalink)
fixitchris


 
 

Re: Data Fetching and system.windows.forms.form & .datagridview

EXCELLENT! Thank YOU.

$cn2 = new-object system.data.SqlClient.SQLConnection("Data
Source=tcp:library;integrated Security=SSPI;Initial Catalog=cbprogram");
$da = New-Object system.data.sqlclient.sqldataadapter("select * from cblog",
$cn2);
$tbl = New-Object system.data.dataset;
$cmd = new-object system.data.sqlclient.sqlcommand("select * from cblog",
$cn2);
$cn2.Open();
if ($cmd.ExecuteNonQuery() -ne -1)
{
echo "Failed";
}

$da.fill($tbl,"CBLOG");
[reflection.assembly]::loadwithpartialname("system.windows.forms");
$window = New-Object windows.forms.form;
$window.Size = New-Object system.drawing.size @(800,600);

$grid = New-Object windows.forms.datagrid;
$grid.DataSource = $tbl.psobject.baseobject;
$grid.Dock = [system.windows.forms.dockstyle]::fill;

$window.Text = "ROWS in [dbo].[cbprogram].[cblog] =
$($tbl.Tables.Item(0).Rows.count)";
$window.Controls.Add($grid);
$window.ShowDialog();
$cn2.close()

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
VB 2005 Windows forms Data Structure .NET General
System.Windows.Forms.Form PowerShell
RE: Data error DataGridView DataGridViewComboBoxColumn .NET General
Error with Windows.forms.form PowerShell
[system.Windows.Forms.MessageBox] PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46