|
If I use
MyBindingsource.datasource=(From t in context.Mytable Select t).Tolist
and after :
Mybindingsource.Current.vl1=25
everything is ok.
|
|
|
|
|
dilkonika wrote:
If I use
MyBindingsource.datasource=(From t in context.Mytable Select t).Tolist
and after :
Mybindingsource.Current.vl1=25 everything is ok.
Is it the same Mytable? Apparently this one has a field for vl1 that is assignable - as in, not a view.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
It's "something" in the EF framework. The first query is a simple one, and it may generate a decent update-statement for it- while that may be a bit harder for the second query.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am writing a code for my CIS-115 class. I have all of the information that I need in it (I think!), but I cannot get ALL of my calculations to execute correctly; only 2 of 5 come out right. Am I allowed to post it here to get help?
|
|
|
|
|
Yes, but don't ask for anyone to write your code for you. That's the restriction.
|
|
|
|
|
You will need to design an application that will receive the customer type and its units of utility used for the billing duration. The application will calculate and display the cost per unit based on the customer type and the total charges for that billing cycle. Calculate the charges using the following data.
Customer Type Units Consumed Cost per unit ($)
Commercial <= 1,000 $0.50 per unit
Commercial 1,000 < $0.50 per unit
Industrial < 800 $0.65 per unit
Industrial 800 <= 2,000 $0.55 per unit
Industrial 2,000 < $0.50 per unit
Residential < 500 $0.85 per unit
Residential 500 <= $0.75 per unit
Make sure that the units consumed entered is a positive number and the customer Type is valid; otherwise your program should display an error message and ask for the data to be entered again until the user enters valid data. Test your algorithm with the following three sets of data.
Test case 1: Units used of 799, Customer Type is Industrial
Test case 2: Units used 500, Customer Type is Residential
Test case 3: Units used 800, Customer Type is Industrial
Test case 4: Units used 1000, Customer Type is Commercial
Test case 5: Units used 499, Customer Type is Residential
|
|
|
|
|
Sub Main()
Dim customerType As String
Dim unitsConsumed As Decimal = 0
Dim costPerUnit As Decimal = 0
Dim totalCharges As Decimal = 0
Do
Console.Write("Enter the customer type as commercial, industrial, or residential: ")
customerType = Console.ReadLine()
While customerType <> "commercial" And customerType <> "industrial" And customerType <> "residential"
Console.WriteLine("ERROR - Enter commerical, industrial, or residential.")
Console.Write("Enter the customer type as commercial, industrial, or residential: ")
customerType = Console.ReadLine()
End While
Console.Write("Enter the units consumed: ")
unitsConsumed = Console.ReadLine()
While unitsConsumed < 0
Console.WriteLine("ERROR - Please enter a value greater than zero.")
Console.Write("Enter the units consumed. ")
unitsConsumed = Console.ReadLine()
End While
If unitsConsumed <= 1000 Then
costPerUnit = 0.5
If unitsConsumed < 1000 Then
costPerUnit = 0.5
If unitsConsumed < 800 Then
costPerUnit = 0.65
If (unitsConsumed > 800) And (unitsConsumed <= 2000) Then
costPerUnit = 0.55
If unitsConsumed > 2000 Then
costPerUnit = 0.5
If unitsConsumed < 500 Then
costPerUnit = 0.85
If unitsConsumed >= 500 Then
costPerUnit = 0.75
End If
End If
End If
End If
End If
End If
End If
totalCharges = unitsConsumed * costPerUnit
Console.WriteLine("The total charges are: " & totalCharges)
Console.ReadLine()
Loop
End Sub
|
|
|
|
|
This is the code that I have, but only Test Case 1 and 4 execute correctly. I have sat here for hours looking through my book and lectures, but I'm just blind to my problem. Thank you, in advance, if you are able to help me!
|
|
|
|
|
Look at your nested if statement 100 meets these criteria 1000, 1000, 800 500 so which value will be returned, the first of course.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Another day, another hint.
If x < 1000 Then
If x < 800 Then
If x > 2000 Then
End If
End If
End If Find me a number smaller than 1000, but larger than 2000.
There's another problem, take a look at the example-rules;
Member 10728667 wrote: Commercial <= 1,000 $0.50 per unit
Commercial 1,000 < $0.50 per unit If think the first price is for commercial stuff if you buy 1000 items or less, and the second price would be if you buy MORE than 1000 items. That's prolly what the position of the operator should imply. Back to the code;
If unitsConsumed <= 1000 Then
costPerUnit = 0.5
If unitsConsumed > 1000 Then
Now that I switched the operator to what it probably should be, does it help to diagnose the error?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The easy thing to do is put a breakpoint and then step through your code and you'll see exactly what is happening. It should be very easy to solve at that point.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have a devexpress Master-View gridcontrol , bound to Entity bindingsource. Programatically I update some records on bindingsource , but the Gridcontrol is not refreshed with new data. I have used the following methods : ( GridviewMaster - is Master View , GridviewChild - is Detail view )
GridControl1.RefreshDataSource()
GridControl1.MainView.RefreshData()
GridControl1.DefaultView.RefreshData()
GridViewMaster.RefreshData()
GridViewChild.RefreshData()
But without success.I know that the bindingsource is updated , but the Gridcontrol is not. Only when i close and open the form again the gridcontrol is updated.
What can I do ? ( without querying the database)
Thank you !
|
|
|
|
|
Hello !
Is there any free Twain for .NET that I can use on a Visual basic 2013 Application ?
Thank you !
|
|
|
|
|
|
Hi guys,
I have the following code that will send an email from Visual Basic project using data from an SQL row called "Email". It works fine. However, it appears it is only showing one email from SQL into the TextBox. Therefore, only sending it to one email address. I have two email addresses stored in the database for testing but only one of them get the email message.
Here is the code:
Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=FigClubs;Integrated Security=True;Pooling=False")
Dim cmd As SqlCommand = New SqlCommand("SELECT Email FROM Members", con)
con.Open()
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataTable As DataTable = New DataTable
myDA.Fill(myDataTable)
con.Close()
con = Nothing
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(My.Settings.ClubEmail, My.Settings.EmailPassword)
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(TextBox4.Text)
e_mail.To.Add(EmailTextBox.Text)
e_mail.Subject = TextBox1.Text
e_mail.IsBodyHtml = False
e_mail.Body = TextBox2.Text
Smtp_Server.Send(e_mail)
MsgBox("Your email has been sent.")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
Me.Close()
Any help you can provide with this would be greatly appreciated.
Thanks,
Dan
|
|
|
|
|
Your Select statement extracts the Email fields from your database and fills your DataAdapter. How do the email addresses then get to EmailTextBox ?
|
|
|
|
|
Hi Richard,
I am using the Dataset to populate the EmailTextBox.
Cheers,
Dan
|
|
|
|
|
And what do you see in the textbox at the time you try to create the mail message? It would really help people to help you, if you provided complete details of what you see when you run your code.
|
|
|
|
|
Hi Richard,
Thanks for the reply.
I did mention in my original post that only one of the stored email addresses show in the TextBox.
So basically, when I run the code, only one of the two email addresses in the Database is showing in the EmailTextBox and not the two that are stored.
My plan is to show any amount of email addresses that are stored in the database to be entered into the EmailTextBox when the application is run.
Cheers,
Dan
|
|
|
|
|
OK, and how do you think we can guess why there is only one email address showing? We have no idea what the content of the Email field is, how you are binding from your DataAdapter to your EmailTextBox etc. As I said before, we really need all the information you have, we cannot see what is going on on your screen.
|
|
|
|
|
Hi Richard,
All of the code I am using is placed on this thread. When I execute the code, I see an email form with an email address in the To: box. This is one of the email addresses in my database. It works just fine. However, as I have said, I have more than one email address in the Database but only one shows. I can't see how me providing a screenshot of an email form is going to solve the issue. All I want to know is how to place more than one value from an SQL row into one textbox, preferably so an email message can be sent to more than one email address at a time.
So, if you read my first post in this thread, it explains the issue in detail and provides all of the code I am using.
Thanks.
|
|
|
|
|
Dan O'Riordan wrote: All of the code I am using is placed on this thread.
Clearly not, as you haven't posted any code that would take the email address from the DataSet and put it in the TextBox .
You're going to need to loop through all the rows of the DataSet and join the addresses together with a comma before putting them in the TextBox .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
I did mate:
Calls the Data from the DQL Database:
Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=FigClubs;Integrated Security=True;Pooling=False")
Dim cmd As SqlCommand = New SqlCommand("SELECT Email FROM Members", con)
con.Open()
Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim myDataTable As DataTable = New DataTable
myDA.Fill(myDataTable)
con.Close()
con = Nothing
This tells the data to display in the TextBox:
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(My.Settings.ClubEmail, My.Settings.EmailPassword)
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(TextBox4.Text)
e_mail.To.Add(EmailTextBox.Text)
e_mail.Subject = TextBox1.Text
e_mail.IsBodyHtml = False
e_mail.Body = TextBox2.Text
Smtp_Server.Send(e_mail)
MsgBox("Your email has been sent.")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
It obviously works because one of the emails in the Database is displayed in the TextBox in question and the email is sent without error to this address.
The TextBox for the To: field is bound to the Datatable called Members. In SQL this data has a field called "Email, where I am getting the email addresses from and displaying them into the TextBox.
Me.MembersTableAdapter.Fill(Me.MembersDataSet.Members)
Can you tell me please how to loop it and separate them with Commas? I have searched everywhere for a solution and not getting anywhere.
Thanks.
|
|
|
|
|
So you're using data-binding to move the data from the DataTable to the TextBox ? That's not going to work; a TextBox will only bind to a single record.
You can either remove the binding and loop through the values in code:
string[] addresses myDataTable.Rows.Cast<DataRow>().Select(row => (string)row[0]).ToArray();
EmailTextBox.Text = string.Join(", ", addresses);
Or you can change the query to return a single row with the concatenated addresses in it, using one of these methods[^]:
SELECT Stuff((SELECT ', ' + Email FROM Members FOR XML PATH(''), TYPE).value('.', 'varchar(max)'), 1, 2, '') As Email;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|