Hi Freinds,
I make the application upload the file and download from database on Gridview its working fine but when i tried to delete the file using rowdeleting in gridview its showing error like
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
Loading
Sanjeeb LenkaPosted Aug 30, 2013, 6:25 AM
check once using varbinary(8000)
Rocky RockyPosted Aug 30, 2013, 5:52 AM
Oh Thanks You Friend in web application requirement is
create table travel_claim
(
request_id int identity ,
Deaprturedate datetime,
From_place varchar(20),
to_place varchar(20),
Lodge varchar(20),
Food Varchar(20),
Dailyclaim varchar(20)
)
My aspx page:
departuredate=(jquerydatepicker)
from =textbox
to =textbox
Lodge = textbox
Food = textbox
dailyclaim = textbox
ADD(after the button entire details ll display on gridview below )
if i possible make a Upload content in Folder along with gridview?
in that gridview row can be deleted depends on the request_id as the same i can able delete the uploaded content alond with that id?
kindly do the need full?
Sanjeeb LenkaPosted Aug 30, 2013, 5:43 AM
i afraid it will not support.
from my experience don't store the files in to database. store it in folder in your project and sve the path in database.
Rocky RockyPosted Aug 30, 2013, 5:33 AM
varbinary(max) ll work on mssql2000, i ve that batabase only
Sanjeeb LenkaPosted Aug 30, 2013, 5:24 AM
check the attached sample it worked for me. just change the connection string in web.config and make data column to varbinary(MAX).
Rocky RockyPosted Aug 30, 2013, 5:04 AM
Its accepting with in 7 kb files oly . i checked on net varbinary allows up to 2GB
protected void Upload(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string contentType = FileUpload1.PostedFile.ContentType;
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
byte[] bytes = br.ReadBytes((Int32)fs.Length);///// i thnk may be here problem
conn.Open();
string query = "insert into tblFiles values (@Name, @ContentType, @Data)";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@Name", filename);
cmd.Parameters.AddWithValue("@ContentType", contentType);
cmd.Parameters.AddWithValue("@Data", bytes);
cmd.ExecuteNonQuery();
conn.Close();
BindData();
Response.Redirect(Request.Url.AbsoluteUri);
}
how to do it?
Sanjeeb LenkaPosted Aug 30, 2013, 3:37 AM
change it to varbinary(MAX) and check once.
Rocky RockyPosted Aug 30, 2013, 3:27 AM
Data =varbinary(3000)
i making the travel claim like the details
departuredate=(jquerydatepicker)
From = textBox
To =TextBox
Lodge=textbox
foodBill=textbox
Daily Claim=textbox
Bill references=textbox Upload(button)
Add(After press entire details Shwn On GridView)
That purpose only i m asking these
Sanjeeb LenkaPosted Aug 30, 2013, 3:05 AM
what is the datatype of Data in sql server.
and one question why you are storing total file to database as it will waste database space and memory.
Rocky RockyPosted Aug 30, 2013, 3:02 AM
I thnk
cmd.Parameters.AddWithValue("@Data", bytes);
in Upload control
these line is the problem its accepting size only bytes format.
if the size is kb,mb means wont accepted it and giving that error.
String or binary data would be truncated.
The statement has been terminated.
Sanjeeb LenkaPosted Aug 30, 2013, 3:00 AM
what error msg you are getting plz share.
Rocky RockyPosted Aug 30, 2013, 2:55 AM
After adding The Line also Its Giving same error Message
Sanjeeb LenkaPosted Aug 30, 2013, 2:44 AM
your code looks error free. my be this error coming from file upload control. file upload control allows maximum file size is 4MB for that reason if we upload file size larger than 4MB we will get error.
so put this line in your web.config within <system.web>
<httpRuntime executionTimeout="9999" maxRequestLength="2097151"/>
check and reply. if get any error msg plz post that msg
Rocky RockyPosted Aug 30, 2013, 2:24 AM
i attached My entire code for Upload .lete me back why its not accepting pdf and .jpg files
Sanjeeb LenkaPosted Aug 30, 2013, 2:16 AM
plz share your full code. means on upload it not accepting pdf file.
Rocky RockyPosted Aug 30, 2013, 2:14 AM
its not accepting Pdf Files also..... wat was the problem here
Sanjeeb LenkaPosted Aug 30, 2013, 2:08 AM
thats why i am asking for your grid code.
happy coding.
Rocky RockyPosted Aug 30, 2013, 2:07 AM
Oops I miss the DatakeyNames in My GridView so Only so Its that Error message, When I tried to upload .jpg format
String or binary data would be truncated.
The statement has been terminated.
these error ll be come i added My entire code Let me know
Sanjeeb LenkaPosted Aug 30, 2013, 2:04 AM
plz share your grid aspx design code.
Rocky RockyPosted Aug 30, 2013, 1:56 AM
I Atttached mY Gridview Row Deleting let me know