The error I had before was I can't insert NULL value into resources_id so I added resources_id into insert value to avoid this issue, but when I do it I get this error:
ORA-01722: invalid number C#
Line 56: cmd.ExecuteNonQuery();
.
WHat I did before to avoid this issue is I removed not Null
and left everything null in my table and it works but it caused me other troubles which I found hard to solve, so I decided to go back to main issue and added NOT NULL
to the resources_id in my database. Please help solve this issue.
Another issue I have is resources_id in the parameters is not recognised
MY CODE:
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();
}
}
}
Try to use this
cmd.BindByName = true;
in insert block Or try to delete ":"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.