×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




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();
}
}
}
}

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.