当前位置:编程学习 > C#/ASP.NET >>

标准表达式中数据类型不匹配。

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 Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Data.OleDb;

namespace Excel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        object nothing = Missing.Value;
        private void button1_Click(object sender, EventArgs e)
        {
          Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
            Workbook wb = excel.Workbooks.Open(textBox2.Text, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing);
            Worksheet ws = (Worksheet)wb.Worksheets[1];
            int rowIndex = 1;
            string tName = "";
            string cName = "";
            //int count = 0;
            string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + textBox1.Text + ";Extended Properties=Excel 8.0";
            OleDbConnection myConn = new OleDbConnection(strCon);
            string strCom = " update [yt$] set ispk='Y' where jh='1-1-侧42'";
            myConn.Open();
            OleDbCommand myCommand = new OleDbCommand(strCom, myConn);
 while (ws.get_Range(ws.Cells[rowIndex, 1], ws.Cells[rowIndex, 1]).Text.ToString() != "")
            { cName = ws.get_Range(ws.Cells[rowIndex, 1], ws.Cells[rowIndex, 1]).Text.ToString();
                        tName = ws.get_Range(ws.Cells[rowIndex, 2], ws.Cells[rowIndex, 2]).Text.ToString();
                        strCom = " update [yt$] set ispk='Y' where jh='" + cName + "' and jls='" + tName + "'";
                        myCommand.CommandText = strCom;
                        myCommand.ExecuteNonQuery();
                       rowIndex++;
   }
    
            wb.Close(true, nothing, nothing);
            excel.Quit();
            myConn.Close();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog.FileName;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = openFileDialog.FileName;
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
} --------------------编程问答-------------------- --------------------编程问答-------------------- 哪行有问题? --------------------编程问答-------------------- 调试出错,显示标准表达式数据类型不匹配,请帮忙看一下 --------------------编程问答-------------------- [yt$]是什么 --------------------编程问答-------------------- sheet表名,已经找出问题来了,谢 --------------------编程问答-------------------- 将jls='" + tName + "'";中的'去掉
--------------------编程问答-------------------- strCom = " update [yt$] set ispk='Y' where jh='" + cName + "' and jls='" + tName + "'";

查查里面cName ,tName与数据库的类型是否一致尤其是那个ispk的类型,看看如果是bit类型的就只能填0,1
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,