Thanks Steve. It worked!
Jack
-----Original Message-----
From: systemidotnet-bounces@xxxxxxxxxxxx
[mailto:systemidotnet-bounces@xxxxxxxxxxxx] On Behalf Of Steve Richter
Sent: Thursday, December 27, 2012 2:01 PM
To: .net use with the System i
Subject: Re: [SystemiDotNet] Hello World?
try this Jack. The code reads all the rows of the first srcmbr of a
source file. Then writes the rows to a ListBox.
create a C#, Windows, WPF application.
in ODBC dta source administrator make sure you have a User DSN that is
configed for your as400.
Change the code to use your DSN, user name and password. Then change the
"select from " statement text to select from the file you want.
Should work for there.
-Steve
<Window x:Class="OdbcSample.MainWindow"
xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Menu HorizontalAlignment="Left" Grid.Row="0"
Name="menu1" VerticalAlignment="Top" >
<MenuItem Header="Test" Click="MenuItem_Click"></MenuItem>
<MenuItem Header="CallProc" Click="MenuItem_Click"></MenuItem>
<MenuItem Header="Exit" Click="MenuItem_Click"></MenuItem>
</Menu>
<ListBox x:Name="lbItems" Grid.Row="1"></ListBox>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Data.Odbc;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace OdbcSample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void CallProcedure_dshsq021()
{
var userDsn = "as400_192_168_1_53";
var userName = "FAXMAIL";
var password = "FAXMAIL";
using (var conn = OpenConnection(userDsn, userName, password))
{
// conn is an OdbcConnection instance
OdbcCommand cmd = conn.CreateCommand();
cmd.CommandText = "CALL WLKLIB/DSHSQ021(?,?)";
// Register input parameter for the OdbcCommand
OdbcParameter parm1 = new OdbcParameter("@Shpnum", OdbcType.Char,
10);
parm1.Value = "7392838";
cmd.Parameters.Add(parm1);
OdbcParameter parm2 = new OdbcParameter("@Comments", OdbcType.Char,
50);
parm2.Value = "xyc";
cmd.Parameters.Add(parm2);
cmd.ExecuteNonQuery();
}
}
private void SelectFromSrcmbr( )
{
var userDsn = "as400_192_168_1_53";
var userName = "FAXMAIL";
var password = "FAXMAIL";
using (var conn = OpenConnection(userDsn, userName, password))
{
var cmd = conn.CreateCommand();
cmd.CommandText = "select srcseq, srcdat, srcdta from
srichter.coresrc";
using (OdbcDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
string srcseq = reader.GetString(0);
string srcdat = reader.GetString(1);
string srcdta = reader.GetString(2);
lbItems.Items.Add(srcseq + " " + srcdat + " " + srcdta);
}
}
}
}
private static OdbcConnection OpenConnection(string Dsn, string User,
string Pwd)
{
string connString = "DSN=" + Dsn + "; UID=" + User +
"; PWD=" + Pwd + ";";
var conn = new OdbcConnection(connString);
conn.Open();
return conn;
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
string itemText = null;
if (sender is MenuItem)
itemText = (sender as MenuItem).Header as string;
if (itemText == "Test")
{
lbItems.FontFamily = new FontFamily("Lucida console");
SelectFromSrcmbr();
}
else if (itemText == "CallProc")
{
CallProcedure_dshsq021();
}
else if (itemText == "Exit")
{
this.Close();
}
}
}
}
--
This is the .net use with IBM i (SystemiDotNet) mailing list To post a
message email: SystemiDotNet@xxxxxxxxxxxx To subscribe, unsubscribe, or
change list options,
visit:
http://lists.midrange.com/mailman/listinfo/systemidotnet
or email: SystemiDotNet-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/systemidotnet.
As an Amazon Associate we earn from qualifying purchases.