当前位置: 代码迷 >> ASP.NET >> OdbcDataAdapter.Fill(myds, "test")向dataset中填充时发生异常,苦恼!不道是什么原因
  详细解决方案

OdbcDataAdapter.Fill(myds, "test")向dataset中填充时发生异常,苦恼!不道是什么原因

热度:3308   发布时间:2013-02-25 00:00:00.0
OdbcDataAdapter.Fill(myds, "test")向dataset中填充时发生错误,苦恼!不道是什么原因?
界面如图:

我现在要实现的功能是输出一个.txt文件,代码如下:
C# code
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.Odbc;using System.Data.SqlClient;using System.IO;namespace hkmessages{    public partial class formMonthHk : Form    {        string ConnStr = "Provider=System.Data.Odbc;Dsn=housedbSZ;uid=sa";        //连接数据源        public formMonthHk()        {            InitializeComponent();        }        private void formMonthHk_Load(object sender, EventArgs e)        {            //页面加载时            //string aa = "a b";            //MessageBox.Show(aa.Trim().Replace(" ",""));        }        private void btnOutPut_Click(object sender, EventArgs e)        {            int iyear = Convert.ToDateTime(txtYearMonth.Text.Trim()).Year;            int imonth = Convert.ToDateTime(txtYearMonth.Text.Trim()).Month;            string strWrite;            string hkCause = "";//划款原因                        OdbcConnection mycn = new OdbcConnection(ConnStr);            string strSQL = "select hkmx.i_year,hkmx.i_month,hkmx.s_dkgrzh,hkmx.i_hk_flag,hkmx.s_grxm,hkmx.s_po_grxm,hkmx.dc_je,hkmx.dc_po_je,dkxx.s_grzh,dkxx.s_mobile_phone";                   strSQL += " from yxwt_hkmx hkmx,nd_grdkxx_ma dkxx where hkmx.s_dkgrzh=dkxx.s_grzh and hkmx.i_year="+iyear+" and hkmx.i_month="+imonth;            try            {                StreamWriter hkInfo = new StreamWriter(txtPath.Text,false,Encoding.Default);                //StreamWriter kkInfo=new StreamWriter(                mycn.Open();                DataSet myds = new DataSet();                OdbcDataAdapter mydap = new OdbcDataAdapter(strSQL, mycn);                mydap.Fill(myds, "test");                DataTable mytb = myds.Tables[0];                if (myds.Tables.Count > 0 && mytb.Rows.Count>1)                {                    for (int i = 0; i < mytb.Rows.Count; i++)                    {                        short hk_flag = Convert.ToInt16(mytb.Rows[i][3]);                        string grxm = mytb.Rows[i][4].ToString();                        string poxm = mytb.Rows[i][5].ToString();                        decimal dc_je = Convert.ToDecimal(mytb.Rows[i][6]);                        decimal dc_po_je = Convert.ToDecimal(mytb.Rows[i][7]);                        string handtelephone = mytb.Rows[i][9].ToString();                        if (hk_flag == 100 || hk_flag == 99 || hk_flag == 50)                        {                            hkCause = "尊敬的" + grxm.Trim().Replace(" ", "") + ",您的住房公积金帐户于" + iyear + "年" + imonth + "月的按月划转" + dc_je + "元,您的配偶" + poxm.Trim().Replace(" ", "") + "按月划转" + dc_po_je + "元!";                        }                        switch (hk_flag)                        {                            case 10:                                hkCause = "尊敬的" + grxm.Trim().Replace(" ","") + ",您的住房公积金帐户余额不足,本月的按月划转不成功!";                                break;                            case 11:                                hkCause = "尊敬的" + grxm.Trim().Replace(" ", "") + ",您上月未及时还款,本月的按月划转不成功!";                                break;                            case 12:                                hkCause = "尊敬的" + grxm.Trim().Replace(" ", "") + ",您已经还清贷款而自动停止本月的按月划转!";                                break;                            default:                                break;                        }                        if (handtelephone != "" && handtelephone.Length == 11)                        {                            strWrite = handtelephone + " " + hkCause;                            hkInfo.WriteLine(strWrite);                        }                    }                    lblMsg.Text = "数据成功导出到目标文件!";                }                else                {                    lblMsg.Text = "对不起,"+iyear+"年"+imonth+"月的信息不存在!";                                }                               mycn.Close();                        }            catch(Exception ex)            {                mycn.Close();                lblMsg.Text = "信息导出失败!";            }        }                   }}
  相关解决方案