1
我嘗試比較下一個位置fecmov當前位置,但沒有工作,他們總是不同的,雖然他們不是驗證比較兩行用C#OleDbDataReader擅長
我有這樣的代碼:
string FECMOV;
string filePath = Path.GetDirectoryName(FileUploader.PostedFile.FileName);
if (Path.GetExtension(filePath) == ".xls") {
con1 = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text;MaxScanRows=0\"", filePath);
}
else if (Path.GetExtension(filePath) == ".xlsx") {
con1 = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=Yes;IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text;MaxScanRows=0\"", filePath);
}
using (OleDbConnection connect = new System.Data.OleDb.OleDbConnection(con1)) {
connect.Open();
OleDbCommand command = new System.Data.OleDb.OleDbCommand("select * from [Sheet1$]", connect);
using (OleDbDataReader dr = command.ExecuteReader()) {
if (dr.HasRows) {
while (dr.Read()) {
if (dr.IsDBNull(4)) {
FECMOV = "";
}
else {
FECMOV = dr[4].ToString().Trim();
}
//this validation I try to compare
// the current position with the next
//position fecmov, but not working,
if (FECMOV[a] != FECMOV[a + 1])
{
a=a+1
}
//They are always different though they are not validate
}}}
FECMOV是一個字符串,您所在的位置'了'與字符的位置'A + 1'比較字符。你期望你的字符串一直由同一個字符組成嗎? – Steve
是的,我需要比較第一個寄存器與同一列的第二個寄存器... – YotiS