Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘recordsource’

PRB: Executing Refresh Method of ADO Data Control Causes Syntax and Method Refresh Errors

Symptoms
When you set the RecordSource property of an ADO Data Control to a different SQL SELECT statement and then try to execute the Refresh method, the following error is returned:

Syntax error in FROM clause.which is followed by:

Run-time error ‘-2147217900(80040e14)’:
Method ‘Refresh’ of object ‘IAdodc’ failedor:

Method ‘Refresh’ of object ‘IAdodc’ failed when attempting to refresh an ADODC after setting the recordsource property to another value.The errors occur if the CommandType property of the ADO Data Control is set to adCmdTable.
Resolution
When the CommandType of the ADO Data Control is set to adCmdTable, “SELECT * From” is automatically prepended to the RecordSource value.
Setting the RecordSource to a table name results in a valid SQL statement, such as SELECT * FROM Tablename.
Setting the RecordSource to a SQL SELECT statement, such as Select * From Tablename, results in a SQL statement ofSelect * From Select * From Tablename, which is an invalid SQL statement.

BUG: GPF When RecordSource Property is Blank at Design-Time

Symptoms
A data control causes an application error at runtime if the data controlcontains with a blank RecordSource property at design time and theUpdateControls method is executed. The application error ends Visual Basic.
Resolution
To work around this bug, at design time, set the data control’sDatabaseName property to a database and the RecordSource property to atable in the database. Other controls that are bound to the data control,such as a text box, should also have a value in the control’s DataSourceproperty

BUG: Cell Data Disappears in DBGrid with NumberFormat Set

Symptoms
Setting the NumberFormat property for a column in a DBGrid control to’general number’ or ‘fixed’ sometimes causes all cell data to disappear.
Resolution
At design time, right-click the DBGrid control, and click Retrieve Fieldsto set the column headers automatically to information from the bound datacontrol. Then reset any NumberFormat properties you have modified.
This will fix the problem permanently for this DBGrid control. However, youcan’t use this solution if the DatabaseName and RecordSource properties ofthe data control are not known until run time. In this case, set theNumberFormat property of each relevant column in code. This can be doneimmediately after the data control is connected to the database by usingcode similar to this:

Data1.DatabaseName = “C:\Access\Number.mdb”Data1.RecordSource = “Numbers”Data1.RefreshDBGrid.Columns(0).NumberFormat = “fixed”