Datataset Problem

M

michael haller

In my project i have a textfile witch i import in my c# application.

The datas in the textfile i show the datas in the textfile in my
datagrid..ok that ist not my problem.

Now i have a dataset (dataset.xsd the name is ds_BESR).

How i can my datas in the datagrid into this dataset ds_BESR?

Please help me...i need that. the reasen is my crystal report get the datas
from ds_BESR.
I have no idea how i can set the datas fom dataset ds to dataset ds_BESR.

Here my code...
-----------------

private void DateiEinlesen()

{

// Initialisieren

intRow=0;

Stream myStream;

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\" ;

openFileDialog1.Filter = "BESR Datei (*.V11)|*.V11|Alle Dateien (*.*)|*.*";

openFileDialog1.FilterIndex = 1 ;

openFileDialog1.RestoreDirectory = true ;

openFileDialog1.Title = "Welche Datei wollen sie laden?";

if(openFileDialog1.ShowDialog() == DialogResult.OK)

{

if((myStream = openFileDialog1.OpenFile())!= null)

{

FileInfo fi=new FileInfo(openFileDialog1.FileName);

fileLen=fi.Length;

//textBox1.Text=fileLen.ToString();

FileStream fsi = new FileStream(openFileDialog1.FileName, FileMode.Open,
FileAccess.Read);

StreamReader sri = new StreamReader(fsi,System.Text.Encoding.Default);

strDateipfad = openFileDialog1.FileName;

string strDateTime =
Convert.ToString(System.IO.File.GetCreationTime(strDateipfad));


//------------------------------------

// Einlesen

// ------------------------------------

{

// Status Zeile Initialisieren un starten

this.progressBar1.Minimum =0;

this.progressBar1.Maximum = Convert.ToInt32(fileLen.ToString());

this.progressBar1.Step =1;

progressBar1.Value=0;

// 1 erhöhen...

progressBar1.Value +=1;

Application.DoEvents();

// Create one DataTable with one column.

DataTable MyTable = new DataTable();

DataColumn MyCol1 = MyTable.Columns.Add("Transaktionsart"); // Name der
Spalte...

DataColumn MyCol2 = MyTable.Columns.Add("ESR-Kunden-Nr");

DataColumn MyCol3 = MyTable.Columns.Add("Referenznummer");

DataColumn MyCol4 = MyTable.Columns.Add("Betrag");

DataColumn MyCol5 = MyTable.Columns.Add("Aufgabedatum");

DataColumn MyCol6 = MyTable.Columns.Add("Verarbeitungsdatum");

DataColumn MyCol7 = MyTable.Columns.Add("Gutschriftsdatum");

DataColumn MyCol8 = MyTable.Columns.Add("Mikrofilmnummer");

// Formatierung

dataGrid1.CaptionText="Dateipfad: "+strDateipfad+" vom "+strDateTime;

dataGrid1.ReadOnly = true;


if ( System.IO.File.Exists(strDateipfad) )

{

// Add items.

DataRow NewRow;

System.IO.StreamReader sr = new System.IO.StreamReader(strDateipfad);


while ( sr.Peek() >= 0 )//oder while (-1 != sr.Peek())

{

string strZeilenInhalt = sr.ReadLine();

intRow++;

DataSet4Report myDS4R = new DataSet4Report();

ddRezepte.DataSource = myDS4R.Rezepte();

ddRezepte.DataTextField = "Rezeptname";

ddRezepte.DataValueField = "RezeptID";

ddRezepte.DataBind();

NewRow = MyTable.NewRow();

// Spalte 1

NewRow["Transaktionsart"] = strZeilenInhalt.ToString().Substring(0,3);

// Spalte 2

NewRow["ESR-Kunden-Nr"] = strZeilenInhalt.ToString().Substring(3,9);

// Spalte 3

NewRow["Referenznummer"] = strZeilenInhalt.ToString().Substring(12,27);

// Spalte 4

NewRow["Betrag"] = strZeilenInhalt.ToString().Substring(39,10);

// Spalte 5

//NewRow["Transaktionen"] = strZeilenInhalt.ToString().Substring(49,10);

// Spalte 6

NewRow["Aufgabedatum"] = strZeilenInhalt.ToString().Substring(59,6);

// Spalte 7

NewRow["Verarbeitungsdatum"] = strZeilenInhalt.ToString().Substring(65,6);

// Spalte 8

NewRow["Gutschriftsdatum"] = strZeilenInhalt.ToString().Substring(71,6);

// Spalte 9

NewRow["Mikrofilmnummer"] = strZeilenInhalt.ToString().Substring(77,9);

MyTable.Rows.Add(NewRow);

// 1 erhöhen...

string temp = sri.ReadLine();

fileLen=fileLen-temp.Length -2;

progressBar1.Value +=temp.Length -2;

Application.DoEvents();

}

sr.Close();

// Progressbar zurücksetzen

progressBar1.Value=0;

progressBar1.Update();

lblAnzahl.Text = "Anzahl Zeilen: "+intRow;

lblPfad.Text = "Dateipfad: "+strDateipfad+" vom "+strDateTime;

}


DataView myDataView = MyTable.DefaultView;

// By default, the first column sorted ascending.

myDataView.Sort = "Transaktionsart";

ds.Tables.Add(MyTable);

dataGrid1.DataSource = MyTable;


//da.Fill(ds, "ds_BESR");

//dataGrid1.DataSource = ds.DefaultViewManager;

}

fsi.Close();

}

}

}



thanks for help
 
M

Morten Wennevik

You have a textfile with data?.
Then you (or someone) uses the xml schema definition file "dataset.xsd" to
transfer the data from the textfile to a datagrid?
And your problem is to transfer the data from the datagrid to a dataset
named ds_BESR?

Well, if the datagrid's datasource is a dataset you can obtain it with

ds_BESR = (DataSet)dataGrid1.DataSource;

If you have access to the original dataset you can use it's Copy() method
to copy the structure and content.

ds_BESR = ds.Copy();
 
M

michael haller

Hello Morten

thank you

You have a textfile with data?.
Then you (or someone) uses the xml schema definition file "dataset.xsd" to
transfer the data from the textfile to a datagrid?
And your problem is to transfer the data from the datagrid to a dataset
named ds_BESR?

this is ok........but ...

Now I get the database login screen...why?

here my code:

First input the datas from textfile into the datagrid and after input
ds_BESR => ds_BESR = ds.Copy(); :)

After i open the crystal report..and get a screen database login
screen..why?

Thanks for your help...if you want i send you my project?

Michael

----------------------------------------------
using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

// Wird für File Open benötigt

using System.IO;

//Werden für die Crystal Reports benötigt

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

//Werden für den DB-Zugriff benötigt

using System.Data.Odbc;

using System.Data.OleDb;





namespace BESR

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.OpenFileDialog openFileDialog1;

private System.Windows.Forms.ToolBar toolBar1;

private System.Windows.Forms.ToolBarButton toolBarBttFileOpen;

private System.Windows.Forms.ImageList imageList1;

private System.Windows.Forms.StatusBar statusBar1;

private CrystalDecisions.Windows.Forms.CrystalReportViewer
crystalReportViewer1;

private System.ComponentModel.IContainer components;

private DataSet ds;

private DataSet ds_BESR;

//Report Parameter

CR_BESR crReportDocument;

ParameterDiscreteValue crParameterDiscreteValue;

ParameterField crParameterField;

ParameterFields crParameterFields;

private System.Windows.Forms.TabControl tabControl1;

private System.Windows.Forms.TabPage tabPage1;

private System.Windows.Forms.TabPage tabPage2;

private System.Windows.Forms.DataGrid dataGrid1;

private System.Windows.Forms.ProgressBar progressBar1;

private System.Windows.Forms.ToolBarButton toolBarBttReset;

private System.Windows.Forms.TabPage tabPage3;

private System.Windows.Forms.Label lblAnzahl;

private System.Windows.Forms.Label lblPfad;


// dataset u. datatable initialisieren

private System.Windows.Forms.DataGridTableStyle dataGridTableStyle;


// Lokale Variablen

string strDateipfad = "";

long fileLen;

int intRow=0;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

// dataset u. datatable initialisieren

ds = new DataSet();

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));

this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

this.toolBar1 = new System.Windows.Forms.ToolBar();

this.toolBarBttFileOpen = new System.Windows.Forms.ToolBarButton();

this.toolBarBttReset = new System.Windows.Forms.ToolBarButton();

this.imageList1 = new System.Windows.Forms.ImageList(this.components);

this.statusBar1 = new System.Windows.Forms.StatusBar();

this.crystalReportViewer1 = new
CrystalDecisions.Windows.Forms.CrystalReportViewer();

this.tabControl1 = new System.Windows.Forms.TabControl();

this.tabPage1 = new System.Windows.Forms.TabPage();

this.tabPage2 = new System.Windows.Forms.TabPage();

this.dataGrid1 = new System.Windows.Forms.DataGrid();

this.dataGridTableStyle = new System.Windows.Forms.DataGridTableStyle();

this.tabPage3 = new System.Windows.Forms.TabPage();

this.lblAnzahl = new System.Windows.Forms.Label();

this.progressBar1 = new System.Windows.Forms.ProgressBar();

this.lblPfad = new System.Windows.Forms.Label();

this.tabControl1.SuspendLayout();

this.tabPage1.SuspendLayout();

this.tabPage2.SuspendLayout();

((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();

this.tabPage3.SuspendLayout();

this.SuspendLayout();

//

// toolBar1

//

this.toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {

this.toolBarBttFileOpen,

this.toolBarBttReset});

this.toolBar1.ButtonSize = new System.Drawing.Size(75, 36);

this.toolBar1.DropDownArrows = true;

this.toolBar1.ImageList = this.imageList1;

this.toolBar1.ImeMode = System.Windows.Forms.ImeMode.NoControl;

this.toolBar1.Location = new System.Drawing.Point(0, 0);

this.toolBar1.Name = "toolBar1";

this.toolBar1.ShowToolTips = true;

this.toolBar1.Size = new System.Drawing.Size(864, 44);

this.toolBar1.TabIndex = 1;

this.toolBar1.ButtonClick += new
System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClic
k);

//

// toolBarBttFileOpen

//

this.toolBarBttFileOpen.ImageIndex = 0;

this.toolBarBttFileOpen.Text = "Datei Einlesen";

this.toolBarBttFileOpen.ToolTipText = "BESR Datei Einlesen";

//

// toolBarBttReset

//

this.toolBarBttReset.ImageIndex = 1;

this.toolBarBttReset.Text = "Reset";

//

// imageList1

//

this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;

this.imageList1.ImageSize = new System.Drawing.Size(16, 16);

this.imageList1.ImageStream =
((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.Im
ageStream")));

this.imageList1.TransparentColor = System.Drawing.Color.Transparent;

//

// statusBar1

//

this.statusBar1.ImeMode = System.Windows.Forms.ImeMode.NoControl;

this.statusBar1.Location = new System.Drawing.Point(0, 499);

this.statusBar1.Name = "statusBar1";

this.statusBar1.Size = new System.Drawing.Size(864, 8);

this.statusBar1.TabIndex = 2;

//

// crystalReportViewer1

//

this.crystalReportViewer1.ActiveViewIndex = -1;

this.crystalReportViewer1.BackColor = System.Drawing.SystemColors.Control;

this.crystalReportViewer1.DisplayBackgroundEdge = false;

this.crystalReportViewer1.DisplayGroupTree = false;

this.crystalReportViewer1.DisplayToolbar = false;

this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;

this.crystalReportViewer1.ForeColor =
System.Drawing.SystemColors.ControlText;

this.crystalReportViewer1.Location = new System.Drawing.Point(0, 0);

this.crystalReportViewer1.Name = "crystalReportViewer1";

this.crystalReportViewer1.ReportSource = null;

this.crystalReportViewer1.ShowCloseButton = false;

this.crystalReportViewer1.ShowGroupTreeButton = false;

this.crystalReportViewer1.ShowRefreshButton = false;

this.crystalReportViewer1.Size = new System.Drawing.Size(856, 429);

this.crystalReportViewer1.TabIndex = 3;

this.crystalReportViewer1.Load += new
System.EventHandler(this.crystalReportViewer1_Load);

//

// tabControl1

//

this.tabControl1.Controls.Add(this.tabPage1);

this.tabControl1.Controls.Add(this.tabPage2);

this.tabControl1.Controls.Add(this.tabPage3);

this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;

this.tabControl1.Location = new System.Drawing.Point(0, 44);

this.tabControl1.Name = "tabControl1";

this.tabControl1.SelectedIndex = 0;

this.tabControl1.Size = new System.Drawing.Size(864, 455);

this.tabControl1.TabIndex = 4;

//

// tabPage1

//

this.tabPage1.Controls.Add(this.crystalReportViewer1);

this.tabPage1.Location = new System.Drawing.Point(4, 22);

this.tabPage1.Name = "tabPage1";

this.tabPage1.Size = new System.Drawing.Size(856, 429);

this.tabPage1.TabIndex = 0;

this.tabPage1.Text = "Druckvorschau";

//

// tabPage2

//

this.tabPage2.Controls.Add(this.dataGrid1);

this.tabPage2.Location = new System.Drawing.Point(4, 22);

this.tabPage2.Name = "tabPage2";

this.tabPage2.Size = new System.Drawing.Size(856, 429);

this.tabPage2.TabIndex = 1;

this.tabPage2.Text = "Ansicht/Sortierung";

//

// dataGrid1

//

this.dataGrid1.DataMember = "";

this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;

this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;

this.dataGrid1.Location = new System.Drawing.Point(0, 0);

this.dataGrid1.Name = "dataGrid1";

this.dataGrid1.PreferredColumnWidth = 100;

this.dataGrid1.PreferredRowHeight = 12;

this.dataGrid1.RowHeaderWidth = 20;

this.dataGrid1.Size = new System.Drawing.Size(856, 429);

this.dataGrid1.TabIndex = 0;

this.dataGrid1.TableStyles.AddRange(new
System.Windows.Forms.DataGridTableStyle[] {

this.dataGridTableStyle});

//

// dataGridTableStyle

//

this.dataGridTableStyle.DataGrid = this.dataGrid1;

this.dataGridTableStyle.HeaderForeColor =
System.Drawing.SystemColors.ControlText;

this.dataGridTableStyle.MappingName = "V11";

//

// tabPage3

//

this.tabPage3.Controls.Add(this.lblPfad);

this.tabPage3.Controls.Add(this.lblAnzahl);

this.tabPage3.Location = new System.Drawing.Point(4, 22);

this.tabPage3.Name = "tabPage3";

this.tabPage3.Size = new System.Drawing.Size(856, 429);

this.tabPage3.TabIndex = 2;

this.tabPage3.Text = "Informationen";

//

// lblAnzahl

//

this.lblAnzahl.Location = new System.Drawing.Point(24, 32);

this.lblAnzahl.Name = "lblAnzahl";

this.lblAnzahl.Size = new System.Drawing.Size(680, 16);

this.lblAnzahl.TabIndex = 5;

//

// progressBar1

//

this.progressBar1.Dock = System.Windows.Forms.DockStyle.Bottom;

this.progressBar1.Location = new System.Drawing.Point(0, 507);

this.progressBar1.Name = "progressBar1";

this.progressBar1.Size = new System.Drawing.Size(864, 10);

this.progressBar1.TabIndex = 4;

//

// lblPfad

//

this.lblPfad.Location = new System.Drawing.Point(24, 8);

this.lblPfad.Name = "lblPfad";

this.lblPfad.Size = new System.Drawing.Size(680, 16);

this.lblPfad.TabIndex = 6;

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(864, 517);

this.Controls.Add(this.tabControl1);

this.Controls.Add(this.statusBar1);

this.Controls.Add(this.toolBar1);

this.Controls.Add(this.progressBar1);

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

this.Name = "Form1";

this.RightToLeft = System.Windows.Forms.RightToLeft.No;

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = " Luzerner Kantonalbank BESR Einlesen";

this.tabControl1.ResumeLayout(false);

this.tabPage1.ResumeLayout(false);

this.tabPage2.ResumeLayout(false);

((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();

this.tabPage3.ResumeLayout(false);

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

private void DateiEinlesen()

{

// Initialisieren

intRow=0;

Stream myStream;

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\" ;

openFileDialog1.Filter = "BESR Datei (*.V11)|*.V11|Alle Dateien (*.*)|*.*";

openFileDialog1.FilterIndex = 1 ;

openFileDialog1.RestoreDirectory = true ;

openFileDialog1.Title = "Welche Datei wollen sie laden?";

if(openFileDialog1.ShowDialog() == DialogResult.OK)

{

if((myStream = openFileDialog1.OpenFile())!= null)

{

FileInfo fi=new FileInfo(openFileDialog1.FileName);

fileLen=fi.Length;

//textBox1.Text=fileLen.ToString();

FileStream fsi = new FileStream(openFileDialog1.FileName, FileMode.Open,
FileAccess.Read);

StreamReader sri = new StreamReader(fsi,System.Text.Encoding.Default);

strDateipfad = openFileDialog1.FileName;

string strDateTime =
Convert.ToString(System.IO.File.GetCreationTime(strDateipfad));


//------------------------------------

// Einlesen

// ------------------------------------

{

// Status Zeile Initialisieren un starten

this.progressBar1.Minimum =0;

this.progressBar1.Maximum = Convert.ToInt32(fileLen.ToString());

this.progressBar1.Step =1;

progressBar1.Value=0;

// 1 erhöhen...

progressBar1.Value +=1;

Application.DoEvents();

// Create one DataTable with one column.

DataTable MyTable = new DataTable();

DataColumn MyCol1 = MyTable.Columns.Add("Transaktionsart"); // Name der
Spalte...

DataColumn MyCol2 = MyTable.Columns.Add("ESR-Kunden-Nr");

DataColumn MyCol3 = MyTable.Columns.Add("Referenznummer");

DataColumn MyCol4 = MyTable.Columns.Add("Betrag");

DataColumn MyCol5 = MyTable.Columns.Add("Aufgabedatum");

DataColumn MyCol6 = MyTable.Columns.Add("Verarbeitungsdatum");

DataColumn MyCol7 = MyTable.Columns.Add("Gutschriftsdatum");

DataColumn MyCol8 = MyTable.Columns.Add("Mikrofilmnummer");

// Formatierung

dataGrid1.CaptionText="Dateipfad: "+strDateipfad+" vom "+strDateTime;

dataGrid1.ReadOnly = true;


if ( System.IO.File.Exists(strDateipfad) )

{

// Add items.

DataRow NewRow;

System.IO.StreamReader sr = new System.IO.StreamReader(strDateipfad);


while ( sr.Peek() >= 0 )//oder while (-1 != sr.Peek())

{

string strZeilenInhalt = sr.ReadLine();

intRow++;

NewRow = MyTable.NewRow();

// Spalte 1

NewRow["Transaktionsart"] = strZeilenInhalt.ToString().Substring(0,3);

// Spalte 2

NewRow["ESR-Kunden-Nr"] = strZeilenInhalt.ToString().Substring(3,9);

// Spalte 3

NewRow["Referenznummer"] = strZeilenInhalt.ToString().Substring(12,27);

// Spalte 4

NewRow["Betrag"] = strZeilenInhalt.ToString().Substring(39,10);

// Spalte 5

//NewRow["Transaktionen"] = strZeilenInhalt.ToString().Substring(49,10);

// Spalte 6

NewRow["Aufgabedatum"] = strZeilenInhalt.ToString().Substring(59,6);

// Spalte 7

NewRow["Verarbeitungsdatum"] = strZeilenInhalt.ToString().Substring(65,6);

// Spalte 8

NewRow["Gutschriftsdatum"] = strZeilenInhalt.ToString().Substring(71,6);

// Spalte 9

NewRow["Mikrofilmnummer"] = strZeilenInhalt.ToString().Substring(77,9);

MyTable.Rows.Add(NewRow);

// 1 erhöhen...

string temp = sri.ReadLine();

fileLen=fileLen-temp.Length -2;

progressBar1.Value +=temp.Length -2;

Application.DoEvents();

}

sr.Close();

// Progressbar zurücksetzen

progressBar1.Value=0;

progressBar1.Update();

lblAnzahl.Text = "Anzahl Zeilen: "+intRow;

lblPfad.Text = "Dateipfad: "+strDateipfad+" vom "+strDateTime;

}


DataView myDataView = MyTable.DefaultView;

// By default, the first column sorted ascending.

myDataView.Sort = "Transaktionsart";

ds.Tables.Add(MyTable);

dataGrid1.DataSource = MyTable;


ds_BESR = ds.Copy();

//ds_BESR = (DataSet)dataGrid1.DataSource;

}

fsi.Close();

}

}

}

==========================================================

private void crystalReportViewer1_Load(object sender, System.EventArgs e)

{

//Eigenschaft manuell auf true stellen

this.crystalReportViewer1.DisplayToolbar = true;

//Create an instance of the strongly-typed report object

crReportDocument = new CR_BESR();

crReportDocument.SetDataSource(ds_BESR);



this.crystalReportViewer1.ReportSource = crReportDocument;

this.crystalReportViewer1.Zoom(70);


}
 
M

Morten Wennevik

I'm afraid I do not know why you get the database login screen,
but seeing as you have the dataTable available before setting the datagrid
source, why use ds at all?
You could just add the MyTable to ds_BESR.
 
Top