ORA-01722:无效的号码#2

时间:2014-03-10 21:29:40

标签: c# oracle visual-studio-2012

之前的错误是我无法在resources_id中插入NULL值所以我将resources_id添加到插入值中以避免此问题,但是当我这样做时,我收到此错误:

  

ORA-01722:无效的数字C#

第56行:cmd.ExecuteNonQuery();

我以前做过什么来避免这个问题是我删除not Null并将所有内容保留在我的表中并且它有效但它导致了我发现很难解决的其他麻烦,所以我决定回到主问题并将NOT NULL添加到我的数据库中的resources_id。 请帮助解决这个问题。

我遇到的另一个问题是参数中的resources_id无法识别

我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Configuration;
using System.IO;



public partial class Lecturer_upload_resources : System.Web.UI.Page
{
    string strCon = "Data Source=****;Persist Security Info=True;User ID=****;Password=****;Unicode=false";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridviewData();
        }
    }
    // Bind Gridview Data
    private void BindGridviewData()
    {
        using (OracleConnection con = new OracleConnection(strCon))
        {
            using (OracleCommand cmd = new OracleCommand())
            {
                cmd.CommandText = "select * from resource1";
                cmd.Connection = con;
                con.Open();
                gvDetails.DataSource = cmd.ExecuteReader();
                gvDetails.DataBind();
                con.Close();
            }
        }
    }
    // Save files to Folder and files path in database
    protected void btnUpload_Click(object sender, EventArgs e)
    {
          string filename = Path.GetFileName(fileUpload1.PostedFile.FileName);
        Stream str = fileUpload1.PostedFile.InputStream;
        BinaryReader br = new BinaryReader(str);
        Byte[] size = br.ReadBytes((int)str.Length);
        using (OracleConnection con = new OracleConnection(strCon))
        {
            using (OracleCommand cmd = new OracleCommand())
            {
                cmd.CommandText = "insert into resource1(Resources_id,FileName,fileType,Filedata) values(:Resources_id,:FileName,:FileType,:FileData)";
                cmd.Parameters.AddWithValue(":Resources_id",Resources_id);
                cmd.Parameters.AddWithValue(":FileName", filename);
                cmd.Parameters.AddWithValue(":FileType", "application/word");
                cmd.Parameters.AddWithValue(":FileData", size);
                cmd.Connection = con;
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                BindGridviewData();
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

尝试使用此

cmd.BindByName = true;
插入块中的

或者尝试删除":"