How to round the floating piont values of textbox in vb.net - vb.net

I have textboxes on my form using for txtDueAmount, txtPaidamount, txtDiscount and txtNetBalance. Every time I want that as I press the save button so all the floating point values of textboxes turns into integer and if any value is like 30.5 so it also converters it into 31.
This is my insert query:
Insert("SaleMaster", "SaleID, SaleTotalAmount, SalePaidAmount, SaleDiscount,
SaleNetBalance, SaleDate", txtSaleID.Text & ", " & txtSaleDueAmount.Text &
", " & txtSalePaidAmount.Text & ", " & txtSaleDiscount.Text & ", " &
txtSaleNetBal.Text & ", '" & dtpSale.Value.Date & "'")
Please help me with this.

Just covert to integer using CInt(txtbox.Text)
You should also validate that the textboxs only have numeric values.

Related

Saving Dynamic Values in Database Using Loop

Hello I have a code that creates dynamic textbox and datetimepicker in vb and then I want to save it in my database but my problem is my code saves data more than my dynamic created items. I know that this is happening because my code is inside the 2 loop but i dont know how to remove it from the 2 loops. Please help me thanks.
my code is here:
For Each textbox As TextBox In panelGroupDependent.Controls.OfType(Of TextBox)()
For Each dtp In panelGroupDependent.Controls.OfType(Of DateTimePicker)()
SaveRecord("INSERT INTO `tbl name`(`value1`, `value2`, `value3`) VALUES ('" & txt1.Text & "','" & textbox.Text & "','" & dtp.Value.ToString("yyyy-MM-dd") & "')")
Next
Next
MsgBox("Dependents Records Added Successfully", , "Dependents Records")
You can create your Textboxes and Datetimepickers with the following convention:
Textbox1, Textbox2, Textbox3...
DateTimePicker1, DateTimePicker2, DateTimePicker3...
Then you can use a code like the following:
for i = 1 to Me.panelGroupDependent.Controls.OfType(Of TextBox)().Count()
Dim txtBox As TextBox = CType(Me.Controls("Textbox" & i),TextBox)
Dim dtPicker As DateTimePicker = CType(Me.Controls("DateTimePicker"&i),DateTimePicker)
SaveRecord("INSERT INTO `tablename`(`value1`, `textbox`, `datetimepicker`) VALUES ('" & txtEmpNumber.Text & "','" & txtBox.Text & "','" & dtPicker.Value.ToString("yyyy-MM-dd") & "')")
Next

How to delete rows in ms access VBA based on multiple attributes

How do I delete rows in ms access VBA based on multiple attributes?
I have written the code below, but it doesn't seem to work.
CurrentDb.Execute "DELETE * FROM StaffAtMeeting" & _
"WHERE RoomID =& Me.field1 AND MeetingDate = Me.field2 AND MeetingTime = Me.field3;"
Maybe I am missing some " (Double Quotes) and some & (Ampersands) ?
You are missing open/close " (Double Quotes) and some & (Ampersands)
currentdb.execute "DELETE * " & _
"FROM StaffAtMeeting " & _
"WHERE(((RoomID) =" & me.field1 & " AND (MeetingDate) =#" & me.field2 & "# AND (MeetingTime) =#" & me.field3 & "#));"
When you write a string statement in VBA you need an opening and closing double quotes, the ampersand acts as a concatenation. The underscore lets the code know to continue on the next line.
Since your variables are not part of the string, you have to end the string, concatenate the variable, then reopen the string. The # (pound sign/hash tag/Number sign) signifies SQL you are using a date or time.

How to give expression for a textbox when multiple fields are used in the textbox of rdlc?

Need to display [Feature] - [FeatureStatus] - [FeaturePerComplete]% if feature field has value or else need to display N/A, what expreession do I need to give for this
Try changing
=IIf(Fields!Feature.Value Is Nothing, "N/A",Fields!Feature.Value & " - " & Fields!FeatureStatus.Value & " - " & Fields!FeaturePerComplete.Value & "%")
to..
=IIf(Isnothing(Fields!Feature.Value), "N/A",Fields!Feature.Value & " - " & Fields!FeatureStatus.Value & " - " & Fields!FeaturePerComplete.Value & "%")
This relies on the Feature column being null in those circumstances - will it definitely be null, or will it be blank?

number of query values and destination fields not the same

hello I'm looking to just do a simple reason for what this is not working ... i have tried adding the same column twice, taking out the TextBox2 i just cant get it to work. all that works is if i take the last value out and the last column otherwise it will not work at all and i have now idea why.what i want is it to place a check mark in there to along with the name.
code:
Dim SqlText As String = "INSERT INTO tblEmployeeNames ([EmployeeName],
[UseForDropDown]) VALUES ('" & Trim(TextBox1.Text) & " " &
Trim(TextBox2.Text) & " " & (CheckBox1.Checked) & "')"
You have included the checkbox-state with the first value, you need to separate them with a comma.
Dim SqlText As String = "INSERT INTO tblEmployeeNames ([EmployeeName], [UseForDropDown]) VALUES ('" & Trim(TextBox1.Text) & " " & Trim(TextBox2.Text) & "', " & (CheckBox1.Checked))"
Notice the Checked state doesn't require apostrophes around it.
See SLaks comment as well, you should be using parameterized queries.

DLookup ControlSource

Summary:
I want to display a value (in a text box) stored in another form upon choosing specific values from combo boxes.
I want to pass the two combo box values I have into the DLoopup property but every time I do so it gives me an error.
Below is the code is inserted in the control source property of a text box:
=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] ='" & [Combo5] & "'")
This gives me an "#Error" in the text box.
Also tried the following but gives me "#NAME" error:
=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] = '" & [Combo5.Value] & " And [Program_Name] = '" & [Combo7.Value] & "'")
You need to get your delimiters sorted out. AFAIR Budget Year is a number:
=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] =" & [Combo5])
When you are passing a value to a numeric type field, you do not use delimiters, for text, you use quotes, either 'Abc' or "Abc", for dates, use hash (#) #2012/11/31#.
=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] =" & [Combo5] & " And [Program_Name] = '" & [Combo7.Value] & "'")