473,320 Members | 1,951 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,320 software developers and data experts.

can any one show me where is the mistake in the code below

seshu
156 100+
hi all this is the code
Expand|Select|Wrap|Line Numbers
  1. Public Class Form2
  2.     Dim mycone As New OdbcConnection("myconection")
  3.     Dim mycmnd As New OdbcCommand
  4.     Dim mydr As OdbcDataReader
  5.     Dim str() As String
  6.     Dim arrcnt As Long
  7.     'Dim mysqlstr As String
  8.  
  9.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10.         Dim reccount As Long
  11.         Dim i As Long
  12.         mycmnd = New OdbcCommand("select EmpName from empdetails", mycone)
  13.         mycone.Open()
  14.         mydr = mycmnd.ExecuteReader
  15.         If mydr.HasRows > 0 Then
  16.             reccount = mydr.HasRows - 1
  17.             ReDim str(reccount)
  18.             For i = 0 To reccount
  19.                 str(i) = mydr(0)
  20.                 mydr.NextResult()
  21.             Next
  22.  
  23.         End If
  24.  
  25.     End Sub
  26.  
  27.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  28.  
  29.         Dim i As Integer
  30.         arrcnt = UBound(str)   this is showing me error here  
  31.     mycmnd.CommandType = CommandType.Text
  32.         For i = 0 To arrcnt
  33.             mycmnd.CommandText = "insert into checkout (EmpName) values ('" & str(i) & "')"
  34.             mycone.Open()
  35.             mycmnd.ExecuteNonQuery()
  36.             mycone.Close()
  37.         Next
  38.     End Sub
  39. End Class
Jan 13 '07 #1
6 1063
willakawill
1,646 1GB
hi all this is the code
Expand|Select|Wrap|Line Numbers
  1. Public Class Form2
  2.     Dim mycone As New OdbcConnection("myconection")
  3.     Dim mycmnd As New OdbcCommand
  4.     Dim mydr As OdbcDataReader
  5.     Dim str() As String
  6.     Dim arrcnt As Long
  7.     'Dim mysqlstr As String
  8.  
  9.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10.         Dim reccount As Long
  11.         Dim i As Long
  12.         mycmnd = New OdbcCommand("select EmpName from empdetails", mycone)
  13.         mycone.Open()
  14.         mydr = mycmnd.ExecuteReader
  15.         If mydr.HasRows > 0 Then
  16.             reccount = mydr.HasRows - 1
  17.             ReDim str(reccount)
  18.             For i = 0 To reccount
  19.                 str(i) = mydr(0)
  20.                 mydr.NextResult()
  21.             Next
  22.  
  23.         End If
  24.  
  25.     End Sub
  26.  
  27.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  28.  
  29.         Dim i As Integer
  30.         arrcnt = UBound(str)   this is showing me error here  
  31.     mycmnd.CommandType = CommandType.Text
  32.         For i = 0 To arrcnt
  33.             mycmnd.CommandText = "insert into checkout (EmpName) values ('" & str(i) & "')"
  34.             mycone.Open()
  35.             mycmnd.ExecuteNonQuery()
  36.             mycone.Close()
  37.         Next
  38.     End Sub
  39. End Class
Hi. Replace arrcnt with
Expand|Select|Wrap|Line Numbers
  1. Dim reccount As Long
and don't use the UBound function.

Normal use of a recordset or datareader would be to read it directly into the sql statement. Transferring to an array, in this case, does not appear to provide any benefit. Just wastes time and introduces possible exceptions.

You can also eliminate most of the code with
Expand|Select|Wrap|Line Numbers
  1. "insert into checkout (checkout.EmpName) select empdetails.EmpName from empdetails"
Jan 13 '07 #2
Killer42
8,435 Expert 8TB
...Normal use of a recordset or datareader would be to read it directly into the sql statement. Transferring to an array, in this case, does not appear to provide any benefit. Just wastes time and introduces possible exceptions. ...
But why would arrcnt = UBound(str) produce an error? And seshu, what error did it produce? When reporting an error, always include the details - they are supremely important.
Jan 13 '07 #3
willakawill
1,646 1GB
But why would arrcnt = UBound(str) produce an error? And seshu, what error did it produce? When reporting an error, always include the details - they are supremely important.
Whether or not str has a subscript is conditional upon there being a number of records to initialise it. UBound will fail without an array with subscripts as a parameter. The initial declaration, str(), is just a placeholder and not an array.
Jan 14 '07 #4
Killer42
8,435 Expert 8TB
Whether or not str has a subscript is conditional upon there being a number of records to initialise it. UBound will fail without an array with subscripts as a parameter. The initial declaration, str(), is just a placeholder and not an array.
Interesting - I thought it would just return zero. We live and learn...
Jan 14 '07 #5
seshu
156 100+
Hi. Replace arrcnt with
Expand|Select|Wrap|Line Numbers
  1. Dim reccount As Long
and don't use the UBound function.

Normal use of a recordset or datareader would be to read it directly into the sql statement. Transferring to an array, in this case, does not appear to provide any benefit. Just wastes time and introduces possible exceptions.

sir from this statement
Expand|Select|Wrap|Line Numbers
  1. "insert into checkout (checkout.EmpName) select empdetails.EmpName from empdetails"
will all the records in my table1will be moveing to table2
hope this goes well
i will check it if it fails i think i should take an array right
help me out sir
Jan 16 '07 #6
willakawill
1,646 1GB
will all the records in my table1will be moveing to table2
hope this goes well
i will check it if it fails i think i should take an array right
help me out sir
There is no reason to use an array or recordset. use the statement I gave you and it will work
Jan 16 '07 #7

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

Similar topics

44
by: Mariusz Jedrzejewski | last post by:
Hi, I'll be very grateful if somebody can explain me why my Opera 7.23 (runing under linux) doesn't show me inner tables. Using below code I can see only "inner table 1". There is no problem with...
8
by: ALESSANDRO Baraldi | last post by:
Hi and good evening. I need to show with Lebans RichTextBox a Mime decoded Message. I build an Mail Receiver, with MIME conversion. To show Html Message i think that it's need to rtf...
3
by: ATS | last post by:
I'm trying to set up a slide show on a web page using Javascript. Here is the code I have so far: <script language="javascript"> alert("**in test area 1"); slides = new Array(); slides =...
3
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I need to show a custom control in the DropDown of a Windows.Forms.ToolStripMenuItem (e.g., similar to the Font Color menu item in Word except that the control is specific to my application). I...
2
by: duke123 | last post by:
Hi, I have two divs (image & story) both positioned in a manner so that one overlays the other. The purpose of the code below is to hide one and show the other on a button click. So whenever we...
1
by: bimeldip | last post by:
Hi, I have managed to create codes to display data from the database in a html page.I have gone on to create a page to allow users to manipulate the table via a html page. For instance users will be...
0
by: qutspan | last post by:
When I create taskbox on the form the line beside the box wont show up. it show up untill I have MouseEnter event occur. Also when I have 2 taskbox on the form it does draw the line around the...
1
by: ABHIJIT B | last post by:
Hi, I am using GridView in my web form and binding DataTable in code behind file as given below. gvUsersList.DataSource = dtUserList; gvUsersList.DataBind(); If no records exists in...
3
by: janetopps | last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.