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
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