sql查询出来的结果,想写进access,但是提示出错:数据类型不匹配。
sql字段中的类型是float,access我是设置成数字类型的,那要设置成什么类型就正确了呢,或者用什么函数转换一下数据类型呢。谢谢

解决方案 »

  1.   

    Access 设计表时,除了数据类型选“数字”,下面的字段大小还要选“单精度型”。
      

  2.   

    回笼资金完成比例 销售额完成比例 回笼资金 销售额
    100 100 20 10
    80 6.5 20 10
    70 0.08 20 10
    60 30 20 10
    50 40 20 10
    40 50 20 10
    以上是我的一个表的4个字段 全是文本型,因为数据有6.5和0.08这样的数字
    我的数据库是access的
    前台输出的代码如下:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Data.OleDb;
    public partial class Info : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            this.CreateImage();
        }
       
            
          private void CreateImage()
        {
            int height = 400, width = 600;
            Bitmap image = new Bitmap(width, height);
            //创建Graphics类对象
            Graphics graphics = Graphics.FromImage(image);
            
            
            try
            {
                int sum = 0;
                string P_str_sum = "select SUM(销售额)  from tb_stock";
                OleDbConnection sqlcon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(@"eg.mdb"));
                OleDbDataAdapter myda = new OleDbDataAdapter(P_str_sum, sqlcon);
                DataSet myds = new DataSet();
                myda.Fill(myds);
              
                sum = Convert.ToInt32(myds.Tables[0].Rows[0][0].ToString());
                //清空图片背景色
                graphics.Clear(Color.White);
                Font font = new Font("Arial", 9, FontStyle.Regular);            Font font1 = new Font("宋体", 20, FontStyle.Regular);//
                LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);
                graphics.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
                Brush brush1 = new SolidBrush(Color.Blue);
                graphics.DrawString("冲刺百亿目标  倒计时", font1, brush1, new PointF(150, 30));
                graphics.DrawString("(销售额总计:" + sum + "亿)", new Font("楷体_gb2312", 10), Brushes.Red, new PointF(180, 60));
                //画图片的边框线
                graphics.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);
                Pen mypen = new Pen(brush, 1);
                //绘制横向线条
                int x = 100;
                for (int i = 0; i < 11; i++)
                {
                    graphics.DrawLine(mypen, x, 80, x, 366);
                    x = x + 40;
                }
                Pen mypen1 = new Pen(Color.Blue, 2);
                graphics.DrawLine(mypen1, x - 480, 80, x - 480, 366);
                //绘制纵向线条
                int y = 106;
                for (int i = 0; i < 10; i++)
                {
                    graphics.DrawLine(mypen, 60, y, 540, y);
                    y = y + 26;
                }
                graphics.DrawLine(mypen1, 60, y, 540, y);
                //x轴
                String[] n = { "  合计", "  南京", "  常州", "  无锡", "  苏州", "  上海"};
                x = 60;
                for (int i = 0; i < 6; i++)
                {
                    graphics.DrawString(n[i].ToString(), font, Brushes.Red, x, 374); //设置文字内容及输出位置
                    x = x + 40;
                }
                //y轴
                String[] m = {"100%", " 90%", " 80%", " 70%", " 60%", " 50%", " 40%", " 30%",
                         " 20%", " 10%", "  0%"};
                y = 98;
                for (int i = 0; i < 11; i++)
                {
                    graphics.DrawString(m[i].ToString(), font, Brushes.Red, 25,y); //设置文字内容及输出位置
                    y = y + 26;
                }
                int[] Count = new int[6];
                string P_str_yearID = "select 回笼资金完成比例,销售额完成比例  from tb_stock";
                OleDbDataAdapter my1da = new OleDbDataAdapter(P_str_yearID,sqlcon); 
                DataSet my1ds= new DataSet();
                my1da.Fill(my1ds);
               
                //显示柱状效果
                x = 70;
                for (int j = 0; j< 6; j++)
                {
             
                    Count[j] = Convert.ToInt32(my1ds.Tables[0].Rows[j][1].ToString());
                    SolidBrush mybrush = new SolidBrush(Color.Red);
                    graphics.FillRectangle(mybrush, x, 366 - Count[j] * 26 / 10, 20, Count[j] *26 / 10);
                    x = x + 40;
                }
                graphics.DrawString("统计日期:", new Font("宋体", 15),Brushes.Red, new PointF(380, 60));
                System.IO.MemoryStream MStream = new System.IO.MemoryStream();
                image.Save(MStream, System.Drawing.Imaging.ImageFormat.Gif);//
                Response.ClearContent();
                Response.ContentType = "image/Gif";
                Response.BinaryWrite(MStream.ToArray());
            }
            finally
            {
                graphics.Dispose();
                image.Dispose();
            }
        }
    }
    情况如下:
    1)我要求前台显示数据为6.5和0.08这样的数据饿不要取整数就是完整输出
    2)目前是如果数据库里数据是6或0前台输出就正常想问下为什么会这样怎么修改?