timothybard is right, just Cdbl won't solve it :)
Nick Evan commented: good catch +3
timothybard is right, just Cdbl won't solve it :)
it would be better if you post your code
any way , I think you didn't convert from string to double before calculating,
you wrote like this
Balance.Text = coursefees - installment1.Text
it may work but if user did not enter value and leave the textbox empty then you will have cannot convert string "" to double error
to solve it
Balance.Text = coursefees - CDbl(installment1.Text)
I hope this will help you
1/to use image in the form you need PictureBox Control
2/in order to change the picture whenever the user select item from the comboBox you use the SelectedIndexChanged event, you can get the item that user selected by
dim selectedItem as string
selectedItem = ComboBox.Text
Dim varConnection As New SqlConnection
Dim varDataSet As New DataSet
Dim varAdapter As SqlDataAdapter
Dim varCommand As SqlCommand
Dim varchar As SqlDataAdapter
Dim sql As String
Dim Number_of_Rows As Integer
varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")
sql = "SELECT * FROM tbl_rop"
varCommand = New SqlCommand(sql, varConnection)
varAdapter = New SqlDataAdapter(varCommand)
varAdapter.Fill(varDataSet)
if you removed these lines, return them and see if you still have this problem
:S
Additional information: Cannot find table 0.
TextBox1.Text = varDataSet.Tables(0).Rows(1).Item("Name_User")
there is no table 0 in your dataset
dim Record_num as integer=0
.
.
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.ClickNumber_of_Rows = Me.DataSet11.Tables(0).Rows.Count
If Record_num <> Number_of_Rows - 1 Then
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")
end if
sorry I was mistaken here, Record_num should be initialized with -1 not 0
this time it should really work , just be sure of your dataset that it contains table 0 :S
here are some changes i made to the code.. as always the problem still the same nothing happen... can you figured it out what seems to be the problem....i really appreciate the help
the problem still the same , you mean it just shows the last record ?
if yes , as I said before initializing Record_num with zero inside the button code is your problem
just imagine what will happen if user press Next button for first time
Record_num = 0 and Number_of_Rows =8
the IF statement will compare two numbers and they not equal and it will enter if statement so ,
Record_num = 1
TextBox1.Text = varDataSet.Tables(0).Rows(1).Item("Name_User")
now what will happen if user press Next for second time ?
actually, the same thing
Record_num = 0 and then Record_num =1
while Record_num should equal to 2
so it will show the same row again
I hope I could explain well this time :S
Dim Record_num = 0'i cannot remove the declaration for record num
why you can not remove it ?
declear it in Form1 class not in button code
is it solved ? or you still have problem :S
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim varConnection As New SqlConnection
Dim varDataSet As New DataSet
Dim varAdapter As SqlDataAdapter
Dim varCommand As SqlCommand
Dim varchar As SqlDataAdapter
Dim sql As String
Dim Record_num = 0 ' you do not need this here
Dim Number_of_Rows As Integer = 0 'why zero? this will hold number of rows in your table so you will be sure that once you reached last record you will not increment it
varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")
sql = "SELECT * FROM tbl_rop"sql = "SELECT distinct * FROM tbl_rop"
varCommand = New SqlCommand(varQuery, varConnection)
varCommand = New SqlCommand(sql, varConnection)
varAdapter = New SqlDataAdapter(varCommand)varAdapter.Fill(varDataSet) 'used to get the count of number of rows in a table
Number_of_Rows=varDataSet .Tables("your_table_name").Rows.Count
If Record_num <> Number_of_Rows - 1 Then
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")
End If
the problem that you decleared Record_num inside the next_button code, here each time the user choose next button Record_num will have the same value
define it outside it
public class form1
dim Record_num as integer=0
other thing , you must check if that Record_num is not last record
If Record_num <> Number_of_Rows - 1 Then
Record_num = +1
TextBox1.Text = varDataSet.Tables(0).Rows(Record_num).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(Record_num).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(Record_num).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(Record_num).Item("Phone_number")
i do not understand your code.
>>"this the code for button next n previous" you mean that the same code for next and previous ? each one has its own code
i = 0
[B]For i = 0 To -1[/B]
TextBox1.Text = varDataSet.Tables("tbl_rop").Rows([B]0[/B]).Item("Name_User")
TextBox2.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Hobbies")
TextBox4.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Phone_number")
Next i
TextBox1.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Name_user")
TextBox2.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Hobbies")
TextBox4.Text = varDataSet.Tables("tbl_rop").Rows(0).Item("Phone_number")
first why you are using for loop ? and why it is for 0 to -1 ? maybe you mean
for 0 to some_variable-1
any way i do not think you need for loop inside next or previous button
other thing in the code you always display the content of row 0
TextBox2.Text = varDataSet.Tables("tbl_rop").Rows([B]0[/B]).Item("Date_of_birth")
the problem is when i want to move to the next data nothing appear...the same when i want to look for previous data...
i think your code should display the contents of the first row.
any way , the idea is just to keep track for the records
declear global variable for that call it for example Record_num=0
then in next button incremnt it by one and in the previouse button decrease it by one
after that display the record
TextBox1.Text = varDataSet.Tables("tbl_rop").Rows(Record_num).Item("Name_user")
.....
first thing you need to store the special characters in array , so you will declear array
Dim SC(36) As char
after that store values
SC(0) = "Ï"
SC(1) = "Î"
.......
2-go through the user's string using For loop and for each character in user's string ,which you can get by
x = textbox1.text.Substring(i, 1)
,convert it to the corresponding symbol usingSelect Case
I hope that help you ,try it and if you have questions just ask
Dim InitialValue As New TextBox
Me.Controls.Add(InitialValue)
Dim SalvageValue As New TextBox
Me.Controls.Add(SalvageValue)
Dim AssetValue As New TextBox
Me.Controls.Add(AssetValue)Dim ppdDepreciation As PrintDialog
msngInitialValue = ToSingle(txtInitialValue.Text)
msngSalvageValue = ToSingle(txtSalvageValue.Text)
mintAssetLife = ToInt32(txtAssetLife.Text)
Variables that you declared are different from what you used .
write your code here please
How can I declare the InitialValue.text, txtSalvageValue.Text and TxtAssetLife.Text part of this code?
You do not declare InitialValue.text you just declare variable as textbox.
textbox has many properties one of them is text
we access properties of InitialValue variable by typing InitialValue. what comes after its property
to declear textbox
Dim InitialValue as New TextBox
Me.Controls.Add(InitialValue)
see this link to understand textbox more
p.s. i assumed your variables of type textbox
What do I need to do to correct that?
you need to do as Jx_Man suggest , use Convert.ToSingle
For i = 0 To fLen1 - 1
snglRead1(i) = br1.ReadSingle() 'EXCEPTION thrown right here
Next
maybe you trying to read while you reached the end of file ,
fLen1 = f1.Length
i think this return length on byte , try this
fLen1 = Int(f1.Length / 4)
are you asking about how to loop thru database ? i think like this
count = Me.DataSet.Table_Name.Count
For i = 0 To count - 1
m = Me.DataSet. Table_Name.Rows(i).Item("Column_name")
Select Case m
Case "Leo"
Display image of Leo in Me.DataGrid1.Item(i, 0)
.
.
.
etc
End Select
use boolean varaible to indicate if the user enter correct value for each input like this
If Val(employeeid_txt.Text) > 10 Or Val(employeeid_txt.Text) < 1 Then
MessageBox.Show("Employee Id Outwith Range 1 to 10 ", "Please re-enter", MessageBoxButtons.OK)
Else
[B]correct_EmployeeID=true [/B]
End If
then if all inputs for user are correct , store that entry to your array
if correct_EmployeeID and correct_firstname and correct_surname and correct_gender and correct_position then
EmployeeRec(Index).Employeeid = employeeid_txt.Text
etc ..etc
End if
other thing about your code , your validation based on test the length of the user's input
and that not correct , I can enter something like "abcd" and your program will accept it in the gender input , it is better to compare the user's input string with "male" or "female"
and much better to make user select the gender , and position (use radio button). about the error messages , what if user make more than one error ! many messages will show and that will be annoying , use labels to show the error messages
If Val(employeeid_txt.Text) > 10 Or Val(employeeid_txt.Text) < 1 Then
lable_error_id.text="Employee Id Outwith Range 1 to 10 , Please re-enter" Else
correct_EmployeeID=true
End If
number = number * 4.3
i think that's wrong , you need to add 125,000 to the population grouth each year
number=number+(number*4.3)
Loop Until
count = 200000
other thing why you stop looping untill count=200 000 ?i think you mean number not count
daDocuments.Update(CType(bdsDocuments.DataSource, DataTable))
I think this not right , daDocuments.Update takes two argument one of them is dataset and the other is table
OleDbDataAdapter1.Update(DataSet11, "table_name")
also you can use OleDbCommandBuilder when DataTable maps to a single database table(means database table is not result of join operation)
according to this link DidWork is integer variable
Dim DidWork As Integer = openFD.ShowDialog()
so in this line
If DidWork <> DialogResult.Cancel Then
u make sure that user did not choose cancel button in OpenFileDialog
i hope thats help u :)
I am not sure if I understand you well :S
do you want to clear the textbox from data when user click some button ?
you do like this
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ""
and that for all ur textboxes
but i dont c any changes-inspite i declare it has global variables & else if i use while-loop instead of if-loop And also it returns maxrws=26)
plz helpmm
first of all if is NOT loop u use it to test condition and i do not know why u using the for or while loop !
in ur code each time u press next button what will happen is
1/ make connection to database
2/get number of raws in table
3/goes through ALL the record but u actually display the same one each time .
but when u define global varaible , each time user press next button it will incremnt by one so u keep track of the next record . and NO need for for loop .
i hope its clear now , :S
Ok
Your code won't display the next record , it will always display the same record over and over , any way I think it’s the last one in table not the first.
The problem is u not keep track of which the next record is ! the for loop here dose NOT do that too.
To solve this, first define global variable
Public next_record As Integer
Double click Next Record button to access the code and write this
If next_record <= maxrws - 1 Then
id_txt.Text = ds.Tables("table1").Rows(i).Item("ID").ToString()
name_txt.Text = ds.Tables("table1").Rows(i).Item("Name").ToString()
age_txt.Text = ds.Tables("table1").Rows(i).Item("Age").ToString()
sex_txt.Text = ds.Tables("table1").Rows(i).Item("Sex").ToString()
area_txt.Text = ds.Tables("table1").Rows(i).Item("Area").ToString()
next_record = next_record + 1 ' here we keep track of which the Next record is
Else
………………… ' write what u want to do when it reach the last record , maybe to start all over again or anything
End If
Good luck
it didnot work :sad:
Dim items1 As String
Dim r As Integer = 0
Dim c As Integer = 1
While r < DsStaffName1.StaffAccount.Rows.Count
items1 = DsStaffName1.StaffAccount.Rows(r).Item(c)
CheckedListBox2.Items.Add(items1)
r = r + 1
End Whilei think the error in this statement (DsStaffName1.StaffAccount.Rows.Count) ... but i do not know where or why!!!
bcz i add a label to show me the count .. but it always (0)
:?:
it works with me....just check if the column 1 exist in ur tabel....
and did u clear dataset and fill dataadapter???
hi again..just one column ..so no need to collect it to one string i thought u want to show row of many columns..
any way..ofcourse u need to give c value at start...
Dim c As Integer=number_of_column_u_want
While r < DsStaffName.StaffAccount.Rows.Count
items1 = DsStaffName.StaffAccount.Rows(r).Item(c)
CheckedListBox2.Items.Add(items1)
r = r + 1
end while..
i think this must work i hope...
see.... when u have dataset it represent the table in database that u have
so if u have r rows and c column ...u will go through one row at time and collect all the columns in it..
item=""
with 2 whiles one for rows and inner one for columns collect each cell and add it to item like this.....
item=item & dataset.TabelName.Rows(r).item(c)
CheckedListBox1.Items.Add(item)
hope it is helpful
hi ....
i did this ..first u need dataset and data adapter...
then u will go through each row in dataset and collect the items in one string...then use
CheckedListBox1.Items.Add(the string u collect)
ok i hope this will help
No......it dose have value
i want to write program that read the names of student of specific section from excel file and display it in textbox
actually each cell has name of student
varname=xlsheet.Cells(1, 1).value?
thanks....
i don't have now run time error
but i tried to display result on textbox i always have empty textbox???
hi
I want to know how to read from excel file
i know how to open it but how to store cell's value from excel to the variable
i wrote
varname=xlsheet.Cells(1, 1)
and i got run timeerror
"cast from range to "string not supported