System.IndexOutOfRangeException: There is no row at position 0
-
Hi all, i try to put one image in a table. right now the table is empty.i insert image through front end web form by selecting specified image on clicking browse button.after click the insert button then this error is raised. how can i solve this. "System.IndexOutOfRangeException: There is no row at position 0 " pls help me.
-
Hi all, i try to put one image in a table. right now the table is empty.i insert image through front end web form by selecting specified image on clicking browse button.after click the insert button then this error is raised. how can i solve this. "System.IndexOutOfRangeException: There is no row at position 0 " pls help me.
Could you please post your code too?? I believe, you are updating the 0th row of the DataSet without adding NewRow to it. As the table is empty, the 0th row does not exists. But this is my assumption. Post your code, lets analyze it...
Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot
-
Could you please post your code too?? I believe, you are updating the 0th row of the DataSet without adding NewRow to it. As the table is empty, the 0th row does not exists. But this is my assumption. Post your code, lets analyze it...
Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot
hi venkatesh, you are right, u r assumption is correct. but i want to insert many rows from webform. but this code inserts only one row.if try to insert many rows overwrite and show latest insert record. how to solve this. my code: Dim da As New SqlDataAdapter("Select * From pub_info ", con) Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As New DataSet da.MissingSchemaAction = MissingSchemaAction.AddWithKey con.Open() da.Fill(ds, "pub_info") Dim fn As String = System.IO.Path.GetFullPath(File1.PostedFile.FileName) Dim fs As New FileStream(fn, FileMode.OpenOrCreate, FileAccess.Read) Dim MyData(fs.Length) As Byte Dim sql As String fs.Read(MyData, 0, fs.Length) fs.Close() ds.Tables("pub_info").Rows(0)("logo") = MyData da.Update(ds, "pub_info") pls help me.
-
hi venkatesh, you are right, u r assumption is correct. but i want to insert many rows from webform. but this code inserts only one row.if try to insert many rows overwrite and show latest insert record. how to solve this. my code: Dim da As New SqlDataAdapter("Select * From pub_info ", con) Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As New DataSet da.MissingSchemaAction = MissingSchemaAction.AddWithKey con.Open() da.Fill(ds, "pub_info") Dim fn As String = System.IO.Path.GetFullPath(File1.PostedFile.FileName) Dim fs As New FileStream(fn, FileMode.OpenOrCreate, FileAccess.Read) Dim MyData(fs.Length) As Byte Dim sql As String fs.Read(MyData, 0, fs.Length) fs.Close() ds.Tables("pub_info").Rows(0)("logo") = MyData da.Update(ds, "pub_info") pls help me.
Sophia Rekhi wrote:
Dim da As New SqlDataAdapter("Select * From pub_info ", con) Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As New DataSet da.MissingSchemaAction = MissingSchemaAction.AddWithKey con.Open() da.Fill(ds, "pub_info") Dim fn As String = System.IO.Path.GetFullPath(File1.PostedFile.FileName) Dim fs As New FileStream(fn, FileMode.OpenOrCreate, FileAccess.Read) Dim MyData(fs.Length) As Byte Dim sql As String fs.Read(MyData, 0, fs.Length) fs.Close() ds.Tables("pub_info").Rows(0)("logo") = MyData da.Update(ds, "pub_info")
Change as below,
Dim da As New SqlDataAdapter("Select * From pub_info ", con) Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As New DataSet da.MissingSchemaAction = MissingSchemaAction.AddWithKey con.Open() da.Fill(ds, "pub_info") Dim fn As String = System.IO.Path.GetFullPath(File1.PostedFile.FileName) Dim fs As New FileStream(fn, FileMode.OpenOrCreate, FileAccess.Read) Dim MyData(fs.Length) As Byte Dim sql As String fs.Read(MyData, 0, fs.Length) fs.Close() If ds.Tables("pub_info").Rows.Count=0 Then Dim DR As DataRow = ds.Tables("pub_info").NewRow() ds.Tables("pub_info").Rows.Add(DR) End If ds.Tables("pub_info").Rows(0)("logo") = MyData da.Update(ds, "pub_info")
I think this would solve your problem.
Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot
-
Sophia Rekhi wrote:
Dim da As New SqlDataAdapter("Select * From pub_info ", con) Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As New DataSet da.MissingSchemaAction = MissingSchemaAction.AddWithKey con.Open() da.Fill(ds, "pub_info") Dim fn As String = System.IO.Path.GetFullPath(File1.PostedFile.FileName) Dim fs As New FileStream(fn, FileMode.OpenOrCreate, FileAccess.Read) Dim MyData(fs.Length) As Byte Dim sql As String fs.Read(MyData, 0, fs.Length) fs.Close() ds.Tables("pub_info").Rows(0)("logo") = MyData da.Update(ds, "pub_info")
Change as below,
Dim da As New SqlDataAdapter("Select * From pub_info ", con) Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da) Dim ds As New DataSet da.MissingSchemaAction = MissingSchemaAction.AddWithKey con.Open() da.Fill(ds, "pub_info") Dim fn As String = System.IO.Path.GetFullPath(File1.PostedFile.FileName) Dim fs As New FileStream(fn, FileMode.OpenOrCreate, FileAccess.Read) Dim MyData(fs.Length) As Byte Dim sql As String fs.Read(MyData, 0, fs.Length) fs.Close() If ds.Tables("pub_info").Rows.Count=0 Then Dim DR As DataRow = ds.Tables("pub_info").NewRow() ds.Tables("pub_info").Rows.Add(DR) End If ds.Tables("pub_info").Rows(0)("logo") = MyData da.Update(ds, "pub_info")
I think this would solve your problem.
Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot
Thanx venkatesh, it is fine , while i click insert button.but no image is stored in to table.and after clicking the getimage button same error will raise. but your solutions is very helpful to me. thanks
-
Thanx venkatesh, it is fine , while i click insert button.but no image is stored in to table.and after clicking the getimage button same error will raise. but your solutions is very helpful to me. thanks
Sophia Rekhi wrote:
it is fine , while i click insert button.but no image is stored in to table.and after clicking the getimage button same error will raise.
I don't know how you are implementing this. But I can explain my code, * Selects the record from the table * Checks whether it has record * If no rocord, add a row and update the 0th row * Else just update the 0th row. Its seems you are adding only one image to the table. Why can't your try FileSystem instead of DB?
Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot