473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Get number data from ms access

25
hi guys,

i tried to get some data from my access db. i used repeater to get the data, but i got a problem when i tried to get the data with number type in ms access.
it shown an error.

is there another way to get the data ?

thank you.
Apr 28 '09 #1
7 1666
PRR
750 Expert 512MB
Can you post some sample code? You need to cast before you can "copy" from repeater... also need to check for null values ...
Apr 28 '09 #2
Frinavale
9,735 Expert Mod 8TB
Sample code would really help us understand what you're talking about.

(You can't use a Repeater to retrieve data from a database...but you can use it to display data Retrieved from the database...)

-Frinny

PS

When posting code snippets please remember to use code tags
Apr 28 '09 #3
dbdb
25
here is the code.

Expand|Select|Wrap|Line Numbers
  1. Sub Page_Load (Source As Object, E as EventArgs)
  2.         Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("surat.mdb") & ";"
  3.         Dim MySQL As String = "SELECT no, nosurat, tglsurat, kategori, tujuan, perihal, deskripsi FROM surat"
  4.     Dim MyConn as New OleDBConnection (strConn)
  5.     Dim Cmd as New OleDBCommand (MySQL, MyConn)
  6.     MyConn.Open ()
  7.         rptSurat.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
  8.         rptSurat.DataBind()
  9. End Sub
and for the repeater,

Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ID="rptSurat" Runat="Server">
  2.     <HeaderTemplate>
  3.         <table border=1 cellpadding=5 cellspacing=0 width=50%>
  4.     </HeaderTemplate>
  5.  
  6.     <ItemTemplate>
  7.  
  8.         <tr>        
  9.             <td width=30%><b><font face=Tahoma size=2>No </font></b></td> 
  10.                 <td><font face=Tahoma size=2><%#Container.DataItem("no")%></td></tr>                        
  11.         <tr>
  12.             <td width=30%><b><font face=Tahoma size=2>Tanggal Surat </td> 
  13.                 <td><font face=Tahoma size=2><%#Container.DataItem("tglSurat")%></td></tr>    
  14.         <tr>
  15.             <td width=30%><b><font face=Tahoma size=2>Kategori </td> 
  16.                 <td><font face=Tahoma size=2><%#Container.DataItem("kategori")%></td></tr>
  17.         <tr>
  18.             <td width=30%><b><font face=Tahoma size=2>Tujuan </td> 
  19.                 <td><font face=Tahoma size=2><%#Container.DataItem("tujuan")%></td></tr>
  20.         <tr>
  21.             <td width=30%><b><font face=Tahoma size=2>Perihal </td> 
  22.                 <td><font face=Tahoma size=2><%#Container.DataItem("perihal")%></td></tr>
  23.         <tr>
  24.             <td width=30%><b><font face=Tahoma size=2>Deskripsi Isi </td> 
  25.                 <td><font face=Tahoma size=2><%#Container.DataItem("deskripsi")%></td></tr>                
  26.  
  27.             </ItemTemplate>
  28.  
  29.     <SeparatorTemplate>
  30.         <tr height=25><td></td></tr>
  31.     </SeparatorTemplate>
  32.  
  33.     <FooterTemplate>
  34.         </table>
  35.     </FooterTemplate>
  36.  
  37. </asp:Repeater>                    
  38.  
no : number type in access.
i couldn't get the data, it shown an error.
Apr 30 '09 #4
Frinavale
9,735 Expert Mod 8TB
Ok, next thing we need to know is what the error message says :)
Apr 30 '09 #5
dbdb
25
the error msg is like this :

Expand|Select|Wrap|Line Numbers
  1. Exception Details: System.IndexOutOfRangeException: no
  2.  
  3. Source Error: 
  4.  
  5.  
  6. Line 49:         <tr>        
  7. Line 50:             <td width=30%><b><font face=Tahoma size=2>Letter No </font></b></td> 
  8. Line 51:                 <td><font face=Tahoma size=2><%#Container.DataItem("no")%></td></tr>                        
  9. Line 52:         <tr>
  10. Line 53:             <td width=30%><b><font face=Tahoma size=2>Date </td> 
  11.  
  12.  
  13. Source File: D:\ASPwebsite\srtView.aspx    Line: 51 
  14.  
  15. Stack Trace: 
  16.  
  17.  
  18. [IndexOutOfRangeException: no]
  19.    Microsoft.VisualBasic.CompilerServices.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags) +202
  20.    Microsoft.VisualBasic.CompilerServices.NewLateBinding.CallMethod(Container BaseReference, String MethodName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, BindingFlags InvocationFlags, Boolean ReportErrors, ResolutionFailure& Failure) +150
  21.    Microsoft.VisualBasic.CompilerServices.NewLateBinding.InternalLateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames, Boolean ReportErrors, ResolutionFailure& Failure) +166
  22.    Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames) +22
  23.    ASP.srtview_aspx.__DataBind__control4(Object sender, EventArgs e) in D:\ASPwebsite\srtView.aspx:51
  24.    System.Web.UI.Control.OnDataBinding(EventArgs e) +99
  25.    System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
  26.    System.Web.UI.Control.DataBind() +15
  27.    System.Web.UI.Control.DataBindChildren() +211
  28.    System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
  29.    System.Web.UI.Control.DataBind() +15
  30.    System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +124
  31.    System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +443
  32.    System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +51
  33.    System.Web.UI.WebControls.Repeater.DataBind() +75
  34.    ASP.srtview_aspx.Page_Load(Object Source, EventArgs E) in D:\ASPwebsite\srtView.aspx:14
  35.    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
  36.    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
  37.    System.Web.UI.Control.OnLoad(EventArgs e) +99
  38.    System.Web.UI.Control.LoadRecursive() +50
  39.    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
  40.  
  41.  
error in line 51
May 1 '09 #6
Frinavale
9,735 Expert Mod 8TB
I see your problem.

On line 7 of your VB code:
@dbdb
You are assigning the DataSource of the repeater to the return value of the ExecuteReader() method.

The ExecuteReader method does not return a Table or any other item that can properly be used as a data source. It returns an OleDbDataReader Object. You would have to use this object (read from the data stored within it) to create a data source that could properly be used with the Repeater.

You could do that, but I'm going to recommend using the OleDataAdpater class to fill a DataSet. Once the OleDataAdapter's Fill method is used to fill a DataSet, the DataSet will contain DataTables which you can use as a data source for your repeater. In your case it's likely that only 1 table will be in the DataSet....so this should be rather straightforward.

Look into how use DataAdapters and DataSets....and if you're really curious, look up how to use a DataReader properly.
May 1 '09 #7
The error indicates that the repeater is attempting to read an index that is not present on the datasource.

Make your select statement in a query so that you can see the data it returns. Double check the spelling of your column names and the corresponding indexes used by the data repeater.
May 1 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
5
by: Geoff Cayzer | last post by:
At http://www.blueclaw-db.com/tips_tricks.htm I came across a section which is included below and was hoping for some comment on the article. -------------- Almost never use this auto-number...
3
by: CSDunn | last post by:
Hello, I have a situation with MS Access 2000 in which I need to display report data in spreadsheet orientation (much like a datasheet view for a form). If you think of the report in terms of what...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
7
by: astro | last post by:
Anyone have suggestions on where to troubleshoot this error? Background: -Access 2k v. 9.0.6926 sp3 - front and backend on production server (wiindows 2k) -accessed via Citrix -front-end is...
29
by: james | last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old database file that has the date(s) stored in it as number of days. An...
4
by: JaredEmery | last post by:
Hello all, It's my first database, and I have a query that shows me the quantity, material, length, width and thicknesses of parts, and I'm using these figures to do some arithmetic on a report...
8
by: King | last post by:
Hi I have following MS Acess query Here is the query ID Name Prgm ID Client ID Date Start Time End Time Minutes C4 Trisha TIP DEK0703 7 /7 /2006...
15
by: Hexman | last post by:
Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details...
3
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.