Hallo bin neu hier und kenne mich mit C# und ADO.NET nicht wirklich aus.
also ich habe folgendes vor,ich versuche eine Exceltabelle mit Visual c# 2008 einzulesen und dann nur die zeilen in denen etwas drinsteht zu filtern und dann ausgeben zu lassen.
Tabelle sieht grob so aus:
zb Spalte : B
1 frei
2 TEXT
3 TEXT
4 frei
5 TEXT
nun will ich nur die zeilen ausgeben lassen in denen TEXT steht also B 2,3 und 5 usw...
folgendes hab ich schon geschrieben:
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: 47: 48: 49: 50: 51: 52:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.OleDb; using System.Reflection;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
string connetionString = null; OleDbConnection connection; OleDbDataAdapter oledbAdapter; int i; connetionString ="Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source=U:\\tabelle1.xlsx;" + "Extended Properties=\"Excel 12.0;HDR=NO\";";
connection = new OleDbConnection(connetionString);
connection.Open(); DataTable dt = new DataTable(); oledbAdapter = new OleDbDataAdapter("select * from [Sheet1$B:B]",connection); oledbAdapter.Fill(dt);
oledbAdapter.Dispose(); connection.Close();
for (i = 0; i <= dt.Rows.Count - 1; i++) { MessageBox.Show (dt.Rows[i].ItemArray[0] + "" +dt.TableName); } }}} |