|
Well, here is my code for the count function:
Public Function count(ByVal search As String, ByVal startDate As String, ByVal endDate As String) As Integer<br />
Dim number As Integer<br />
Dim pubs As New SqlConnection(ConfigurationManager.ConnectionStrings("WIA_Report_Builder.My.MySettings.wiaConnectionString").ConnectionString)<br />
'pubs = ConfigurationManager.ConnectionStrings("wiaconnectionstring")<br />
'pubs.ConnectionString = ConfigurationManager.ConnectionStrings("WIA_Report_Builder.My.MySettings.wiaConnectionString").ConnectionString<br />
Dim connection As DbConnection = New SqlConnection()<br />
connection.ConnectionString = pubs.ConnectionString<br />
Dim cmd As DbCommand = connection.CreateCommand()<br />
cmd.CommandType = CommandType.Text<br />
Select Case search<br />
Case "TotalAdultPart"<br />
cmd.CommandText = "Select Count (*) from Demographics where AgeatEnroll >= 22"<br />
Try<br />
connection.Open()<br />
number = cmd.ExecuteScalar<br />
<br />
Catch ex As Exception<br />
Finally<br />
connection.Close()<br />
End Try<br />
....<br />
<br />
End Select<br />
Return number<br />
<br />
end function<br />
|
|
|
|
|
Stepping through the code line by line will tell you where the error is. All you have to do is set a breakpoint on the first line in the method code, then run your app. The debugger will stop the code when it hits the breakpoint. Then all you have to do is single-step until you reach the error.
Aptiva Dave wrote: Dim pubs As New SqlConnection(ConfigurationManager.ConnectionStrings("WIA_Report_Builder.My.MySettings.wiaConnectionString").ConnectionString)
The most obious failure here that can cause the error you're seeing is that ConfigurationManager.ConnectionStrings("WIA_Report_Builder.My.MySettings.wiaConnectionString") may have returned Nothing, on which you're trying to retrieve the value of the ConnectionString property.
From the looks of things, you're having problems retrieving the connection string from a configuration file, correct??
Also, you've (tried to) created a couple of SqlConnection objects. You only need one.
|
|
|
|
|
The problem I have using a break point and debugging that way is that I can get the program to run on my profile of my machine by just running the exe outside of vs 2005.
I don't believe that the issue is from getting to the connection string, but where do you see the multiple SqlConnection objects?
|
|
|
|
|
One possibility is to have your .exe program write a line to a text file after every couple of lines of code in the area where you think the problem is. Then you can see what the last line written was -- you know the error is after that, but before the next line write.
Also perhaps try simply writing the values of the variables in question to a file during the run and see what gets written.
These techniques have helped me in the past.
|
|
|
|
|
That sounds like a good idea. Don't know why I didn't think to do that. Guess I frustrated a bit with it not working and with all of my other help desk calls today.
Anyways, I'll try that when I get back to work tomorrow. Thanks
|
|
|
|
|
Then create another user on your machine and try it.
Better yet, get VMWare or Microsoft's Virtual PC's, install an O/S on it, then your app, and try it again.
|
|
|
|
|
I want to be able to modify a control on my mainform (Form1) from a backgroundworker on Form2. If I first open Form2 I can make it happen by calling the BGW from the button on Form2. However, I cannot call the BGW on Form2 directly from Form1. I don't see why not.
Thanks!
Public Class Form2
Private Delegate Sub SetTextBoxTextDelegate(ByVal text As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.BackgroundWorker1.RunWorkerAsync()
End Sub '
Private Sub SetTextBoxText(ByVal text As String)
Form1.TextBox1.Text = text
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Me.Invoke(New SetTextBoxTextDelegate(AddressOf SetTextBoxText), "Set this text")
End Sub
End Class
|
|
|
|
|
No one can help me??
|
|
|
|
|
Patience.
You shouldn't be updating Form1 controls from Form2 at all. Form2 would be unable to exist without an instance of Form1 if you did. This violates encapsulation and OOP principles.
Form2 should be exposing events that Form1 can subscribe to, where then, Form1 can update it's own controls without Form2 knowing anything about it.
|
|
|
|
|
OK, that helps.
BGW.reportprogress is what I need I think.
Thanks
|
|
|
|
|
Hi All,
I want to broadcasting some audio over LAN, But I don't know how to do it.
Let me explain it clearly, suppose I have a server and some clients connected to it. Now I want if I play some audio file on my server then that audio file must be played on the clients too.
Can anyone please help me?
Regards,
Paramhans
|
|
|
|
|
Check into Microsoft's Media Encoder 9.0 SDK. It'll let you setup and broadcast audio and video. The client's will, of course, have to be running Media Player and connect to the URL exposed by your audio server to connect to.
|
|
|
|
|
Hello,
I have a vb.net application that runs on a server. There are five client PC's that are connected to the server and all the data is saved on the server from my vb.net application.
To add a record, two sql runs under Commit transaction. One runs an insert statement while the other updates a record.
However, I have noticed a error. The update statement has lot of other fields which are stored correctly, but sometimes (say one out of 100 record) it doesnt stores the correct value to a numeric field. This field is integer and the data is stored from a text box.
This is creating a lot of trouble in my application. Please help.
|
|
|
|
|
That description isn't specific enough to solve your problem. You are going to have to do some digging around in your application before we can help you.
Have you stepped through the code? Have you checked the values going to the database? Have you parsed the text box correctly? Can you recreate the scenario in which the value is wrong? If not, what investigations have you done to determine what the scenarios the number is wrong?
|
|
|
|
|
Hill all
I thought it would be the right place to post this Question in this Forum. Because its a lot Problems on VB than SQL. i have a Problem with one of my Parameters. i have the Following Procedure.
<br />
USE [ValRollClients]<br />
GO<br />
<br />
SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO<br />
ALTER Proc [dbo].[Save_Client] <br />
(<br />
--Carry Original values before Update<br />
@Original_Client_ID int,<br />
@Original_Client_Name varchar(50),<br />
@Original_Contact_Person varchar(20),<br />
@Original_Purchase_date datetime,<br />
@Original_Client_Address varchar(50),<br />
@Original_Client_Telephone varchar(20),<br />
@Original_Client_Cell_No varchar(20),<br />
@Original_SerialNumber varchar(20),<br />
@Original_Product_Status int,<br />
@Original_Client_Email varchar(30),<br />
--Carry values after the update has been done<br />
<br />
@Client_Name varchar(50),<br />
@Contact_Person varchar(20),<br />
@Purchase_date datetime,<br />
@Client_Address varchar(50),<br />
@Client_Telephone varchar(20),<br />
@Client_Cell_No varchar(20),<br />
@SerialNumber varchar(20),<br />
@Product_Status int,<br />
@Client_Email varchar(30)<br />
)<br />
as<br />
Update Clients set<br />
Client_Name = @Client_Name,<br />
Contact_Person = @Contact_Person,<br />
Purchase_date = @Purchase_date,<br />
Client_Address = @Client_Address,<br />
Client_Telephone = @Client_Telephone,<br />
Client_Cell_No = @Client_Cell_No,<br />
SerialNumber = @SerialNumber,<br />
Product_Status = @Product_Status,<br />
Client_Email = @Client_Email<br />
Where<br />
(Client_ID = @Original_Client_ID)<br />
And<br />
(Client_Name = @Original_Client_Name or <br />
@Original_Client_Name IS NUll AND Client_Name Is Null)<br />
And <br />
(Contact_Person = @Original_Contact_Person or <br />
@Original_Contact_Person Is Null And Contact_Person IS Null)<br />
And<br />
(Purchase_Date = @Original_Purchase_date or <br />
@Original_Purchase_date is Null And Purchase_date Is Null)<br />
And <br />
(Client_Address = @Original_Client_Address OR <br />
@Original_Client_Address IS Null And Client_Address is Null)<br />
And<br />
(Client_Telephone = @Original_Client_Telephone OR <br />
@Original_Client_Telephone Is Null And Client_Telephone Is Null)<br />
And <br />
(Client_Cell_No = @Original_Client_Cell_No OR <br />
@Original_Client_Cell_No Is Null And Client_Cell_No IS Null) <br />
And<br />
(SerialNumber = @Original_SerialNumber Or <br />
@Original_SerialNumber is NUll And SerialNumber Is Null)<br />
And<br />
(Product_Status = @Original_Product_Status Or<br />
@Original_Product_Status Is NUll And Product_Status Is Null)<br />
ANd<br />
(Client_Email = @Original_Client_Email Or <br />
@Original_Client_Email is Null And Client_Email Is Null)<br />
<br />
--refreshing the data <br />
;select Client_ID,Client_Name,Contact_Person,Purchase_date,<br />
Client_Address,Client_Telephone,Client_Cell_No,SerialNumber,<br />
Product_Status,<br />
Client_Email <br />
from Clients<br />
Where (Client_ID = @Original_Client_ID)<br />
<br />
<br />
And am Calling the Procedure in vb.net like this
<br />
cmdupdate.CommandText = "Save_Client"<br />
<br />
cmdupdate.CommandTimeout = 0<br />
<br />
cmdupdate.CommandType = CommandType.StoredProcedure<br />
<br />
cmdupdate.Connection = con<br />
<br />
cmdupdate.Parameters.Add("@Client_Name", SqlDbType.VarChar, 50, "Client_Name")<br />
<br />
cmdupdate.Parameters.Add("@Contact_Person", SqlDbType.VarChar, 20, "Contact_Person")<br />
<br />
cmdupdate.Parameters.Add("@Purchase_date", SqlDbType.DateTime, 8, "Purchase_Date")<br />
<br />
cmdupdate.Parameters.Add("@Client_Address", SqlDbType.VarChar, 50, "Client_Address")<br />
<br />
cmdupdate.Parameters.Add("@Client_Telephone", SqlDbType.VarChar, 20, "Client_Telephone")<br />
<br />
cmdupdate.Parameters.Add("@Client_Cell_No", SqlDbType.VarChar, 20, "Client_Cell_No")<br />
<br />
cmdupdate.Parameters.Add("@SerialNumber", SqlDbType.VarChar, 20, "SerialNumber")<br />
<br />
cmdupdate.Parameters.Add("@Product_Status", SqlDbType.VarChar, 4, "Product_Status")<br />
<br />
cmdupdate.Parameters.Add("@Client_Email", SqlDbType.VarChar, 30, "Client_Email")<br />
<br />
<br />
da = New SqlDataAdapter<br />
<br />
da.UpdateCommand = cmdupdate<br />
<br />
Dim prmClient_ID As SqlParameter = cmdupdate.Parameters.Add("@Original_Client_ID", _<br />
SqlDbType.Int, 50, "Client_ID")<br />
<br />
prmClient_ID.SourceVersion = DataRowVersion.Original<br />
<br />
Dim prmClient_Name As SqlParameter = cmdupdate.Parameters.Add("@Original_Client_Name", _<br />
SqlDbType.VarChar, 50, "Client_Name")<br />
<br />
prmClient_Name.SourceVersion = DataRowVersion.Original<br />
<br />
Dim prmContact_Person As SqlParameter = cmdupdate.Parameters.Add("@Original_Contact_Person", _<br />
SqlDbType.VarChar, 50, "Contact_Person")<br />
<br />
prmContact_Person.SourceVersion = DataRowVersion.Original<br />
<br />
<br />
Dim prmPurchase_Date As SqlParameter = cmdupdate.Parameters.Add("@Original_Purchase_date", _<br />
SqlDbType.DateTime, 8, "Purchase_Date")<br />
<br />
<br />
prmPurchase_Date.SourceVersion = DataRowVersion.Original<br />
<br />
<br />
Dim prmClient_Address As SqlParameter = cmdupdate.Parameters.Add("@Original_Client_Address", _<br />
SqlDbType.VarChar, 50, "Client_Address")<br />
<br />
prmClient_Address.SourceVersion = DataRowVersion.Original<br />
<br />
<br />
Dim prmClient_telephone As SqlParameter = cmdupdate.Parameters.Add("@Original_Client_Telephone", _<br />
SqlDbType.VarChar, 20, "Client_Telephone")<br />
<br />
prmClient_telephone.SourceVersion = DataRowVersion.Original<br />
<br />
<br />
Dim prmClient_Cell_No As SqlParameter = cmdupdate.Parameters.Add("@Original_Client_Cell_No", _<br />
SqlDbType.VarChar, 20, "Client_Cell_No")<br />
<br />
prmClient_Cell_No.SourceVersion = DataRowVersion.Original<br />
<br />
<br />
Dim prmSerialNumber As SqlParameter = cmdupdate.Parameters.Add("@Original_SerialNumber", _<br />
SqlDbType.VarChar, 20, "SerialNumber")<br />
<br />
prmSerialNumber.SourceVersion = DataRowVersion.Original<br />
<br />
<br />
Dim prmProduct_Status As SqlParameter = cmdupdate.Parameters.Add("@Original_Product_Status", _<br />
SqlDbType.Int, 4, "Product_Status")<br />
<br />
prmProduct_Status.SourceVersion = DataRowVersion.Original<br />
<br />
Dim prmClient_Email As SqlParameter = cmdupdate.Parameters.Add("@Original_Client_Email", _<br />
SqlDbType.VarChar, 20, "Client_Email")<br />
<br />
prmClient_Email.SourceVersion = DataRowVersion.Original<br />
<br />
<br />
Try<br />
con.Open()<br />
<br />
<br />
da.Update(dsdata)<br />
<br />
con.Close()<br />
<br />
Catch ex As SqlClient.SqlException<br />
<br />
MsgBox(ex.Message)<br />
<br />
End Try<br />
<br />
<br />
<br />
i get an Error when i try to save "Concurency violation:The UodatedCommand Affected 0 records"
What is Wrong with my code
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
A concurrency error (0 rows affected) problem occurs because the data that is used to uniquely identify the record that's being updated no longer (or never did) match the data in the database. Since no record matched the WHERE clause, no update was performed.
Check your code for what you're passing into the SQL stored proc and check the stored proc to make sure it's doing exactly what it should be.
|
|
|
|
|
Good Afternoon Dave
The Problem was the Dimension of the Parameters that i created from the Dimension of the Parameters of the stored procedure and that were created out of gauss work from my mind, that does not match the field from the table. from this i learned that the size of the Field from the table, must apply even down when you create parameters in vb.net,they must remain constant.
Thanks DAVE
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
hi all,
when i copy the contents of word file to rich text box , then formatting is not proper shown . Specially if word file contains table structure or Graphic.
anybody have idea that how can i preserve formatting of word file in richtextbox ?
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
Didn't I answer this yesterday ? If a rch text box was as rich as Word, there would be no market for Word.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
How about if you save as RTF from Word then open it in a rich text box?
|
|
|
|
|
if save as RTF then works well. but i give facility to user to copy some part of word file and paste in richtextbox.
so problem is that check format of data to be copied in richtext box.
have any idea about this thing?
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
Rupesh Kumar Swami wrote: when i copy the contents of word file to rich text box , then formatting is not proper shown .
Of course not. The RTB doesn't support everything Word does, including formatting options. You're not going to be able to "force" this to work using the RichTextBox.
|
|
|
|
|
Hi guys,
I have a program using databindings bound to a dataset. Dataset sizes vary from 2000 - 10000 rows, but form loads are very slow (when filling the datasets etc).
Does anyone have some suggestions on how to speed it up? Would it be quicker to use certain datasets instead of the WHOLE dataset of the db every time? (for example only declaring and using CRMDataset.Organisation instead of just declaring CRMDataset).
Any other ideas? I need to shave a second or 2 off the form load times.
Thanx in advance
Ed
Private Sub ManageContacts_M_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Try<br />
Me.OrganisationTableAdapter.FillWithFullName(Me.CRMDataSet.Organisation)<br />
Me.Vw_ContactsCoursesTableAdapter.Fill(Me.CRMDataSet.vw_ContactsCourses)<br />
Me.ContactTableAdapter.Fill(Me.CRMDataSet.Contact)<br />
Me.Controls.Add(Me.BindingNavigator1)<br />
<br />
'Get distinct list to populate combobox/autocomplete box<br />
Try<br />
For Each dr As DataRow In DH.RunQuery("Select DISTINCT Title FROM Contact WHERE Title <> '' AND Title IS NOT NULL ORDER BY Title ASC").Tables(0).Rows<br />
Me.TitleComboBox.Items.Add(dr("Title"))<br />
Next<br />
Catch<br />
MessageBox.Show("Could not pre-populate comboboxes")<br />
'EHC.HandleError(Err, Me)<br />
End Try<br />
Me.OrganisationBindingSource.Sort = "OrganisationName ASC"<br />
DS = DH.RunQuery("Select * FROM Users WHERE Username = '" + SystemInformation.UserName + "'") 'Gets user access rights<br />
If DS.Tables(0).Rows(0).Item("TrainingAccess") = "True" Then 'Disables button if user does not have access<br />
Me.Button2.Visible = True<br />
Else<br />
Me.Button2.Visible = False<br />
End If<br />
<br />
Me.Vw_ContactsCoursesBindingSource1.Sort = "StartDate ASC"<br />
Me.OrganisationBindingSource.Sort = "FullName ASC"<br />
Me.OrganisationBindingSource.CancelEdit() 'For some reason certain user pcs require this to be reset.<br />
Me.ContactBindingSource.CancelEdit()<br />
Me.Vw_ContactsCoursesBindingSource1.CancelEdit()<br />
Catch err As Exception<br />
Dim EHC As New ErrorHandlerClass<br />
EHC.HandleError(err, Me)<br />
End Try<br />
End Sub
modified on Tuesday, February 19, 2008 3:08 AM
|
|
|
|
|
Gr1mR33p3r wrote: Dataset sizes vary from 2000 - 10000 rows, but form loads are very slow (when filling the datasets etc).
Gr1mR33p3r wrote: Does anyone have some suggestions on how to speed it up?
Simple. Don't retrieve thousands of rows from the database if you're not going to need them frequently.
Retrieve only the columns from only the rows you need to get a form setup. If you only need 30 rows from a table, why retrieve 15,000 of them? This is probably going to require you rewriting a considerable chunk of your data code.
Gr1mR33p3r wrote: DS = DH.RunQuery("Select * FROM Users WHERE Username = '" + SystemInformation.UserName + "'") 'Gets user access rights
If DS.Tables(0).Rows(0).Item("TrainingAccess") = "True" Then 'Disables button if user does not have access
Here's an example of retrieving too much information. You're using "SELECT *" which returns all the columns for the rows specified, but you're only looking at the value of a single column and discarding the rest. Change the SQL to retrieve only that column.
SELECT TrainingAccess FROM Users WHERE Username=...
I would also highly suggest looking into using parameterized queries instead of building them with string concantenation. You're opening youreself up to SQL Injection attacks and well as making your code harder to debug using the methods you are now. Read[^]
|
|
|
|
|
When my program loads there are 3 different main panels. The first panel that comes up at runtime has a tab control on it. The first page of the tab control has a data grid that holds a weekly schedule and the second page holds an editable teacher profile.
When the program first comes up I need this dataGrid to automatically load with data. How do I load the dataGrid with data on program start up and change the schedule when a different teacher is selected?
There is also another panel that has a list box on it. The list box holds the names of different teachers. When a user clicks on the teacher name in the list box the schedule for that teacher on the first page of the tab control is supposed to load into the data grid, but it does not. Also, at program start-up the schedule for the first teacher in the list box is supposed to load into the data grid.
Being this program has several panels that each contain at least one form how should I go about loading the forms on the panels. Should I load a function for each panel when the panel comes up or should I call the function or sub procedure in the main loop of the program.
|
|
|
|
|