Hello,
(Windows forms - SQL Server)
I fill my datagrid with a stored procedure that includes relationships
to lookup tables so that users can see the values of the combobox
selections rather than the key value that are stored in the table.
It works well if the comboboxes are selected when the row is created.
I fails to update the lookup table values if the combobox values are
inserted at a later time or if the combobox selections are changed
later.
The only work-around I know is to clear the form, datset, datagrid and
reload everything.
Here is the stored procedure
\\
CREATE PROCEDURE
dbo.usp_047MSen_sel_ByDevi_TypeConnVolt
(
@fkDevice char(36),
@cmVarchar06 varchar(50) --pkComponentId for Cylinder
)AS SET NOCOUNT ON;
SELECT
c.pkComponentId,
c.fkDevice,
c.fkComponentType,
c.ComponentDescription,
c.QuanSharingConfiguration,
c.QuanConfigured,--
c.QuanActuations,
c.cmVarchar01,
c.cmVarchar02,
c.cmVarchar03,
c.cmVarchar04,
c.cmVarchar05,
c.cmVarchar06,
c.cmNumeric01,
c.cmNumeric02,
c.cmNumeric03,
c.cmNumeric04,
c.cmNumeric05,
c.cmNumeric06,
c.cmNumeric07,
c.cmBit01,
c.cmBit02,
c.cmBit03,
c.cmBit04,
c.cmBit05,
c.cmBit06,
c.cmBit07,
c.cmBit08,
c.cmBit09,
c.cmBit10,
c.cmBit11,
c.cmSmallint01,
v.Voltage, '<<from lookup table
c.cmSmallint02,
c.cmSmallint03,
c.cmSmallint04,
st.SensorType, '<<from lookup table
c.cmSmallint05,
sc.SensorConnection, '<<from lookup table
c.cmUserNote,
c.cmCreatedOn,
c.cmCreatedBy,
c.cmEditedOn,
c.cmEditedBy,
c.cmrowversion
FROM tbl040Cmpt c
left outer JOIN lkp104Voltage v ON c.cmSmallint01 =
v.pkVoltageId
left outer JOIN lkp302SensorType st ON c.cmSmallint04 =
st.pkSensorTypeId
left outer JOIN lkp103SensorConnection sc ON c.cmSmallint05 =
sc.pkSensorConnectionId
WHERE
(c.fkDevice = @fkDevice)
-- fkDevice = 'fc063d9f-62f1-4905-913a-e41f2471f2a7'
AND c.cmVarchar06 = @cmVarchar06 -- pkComponentId - the
-- AND c.cmVarchar06 = 'c6236862-dc3d-4e9d-a688-f57809fcb348' --
pkComponentId - the
AND c.fkComponentType = 7 -- Motion Sensor
ORDER BY c.ComponentDescription
GO
//
Here is the example of the update code
\\
Call UpdateSource2(dal.da040CmptFrm, "tbl040Cmpt")
//
and
\\
Protected Sub UpdateSource2(ByVal dA As SqlDataAdapter, ByVal tbl As
String)
Dim dsDataChanges As New CLIP.dsTables
dsDataChanges = CType(_dataSet1.GetChanges, CLIP.dsTables)
If (Not (dsDataChanges) Is Nothing) Then
Try
dA.Update(dsDataChanges, tbl)
_dataSet1.Merge(dsDataChanges)
_dataSet1.AcceptChanges()
Catch ex As Exception
MessageBox.Show("Exception Message: " & vbCrLf & ex.Message)
MessageBox.Show("Exception Source: " & vbCrLf & ex.Source)
MessageBox.Show("Exception StackTrace: " & vbCrLf & ex.StackTrace)
End Try
End If
End Sub
//
Is there a better way?
Thank you,
dbuchanan 3 2139
DBuchanan,
A lot of text, however your "fails" text does at least me not say much.
Know that if something is a stored procedure or a SQL text string does not
append any thing in behaviour to a procedure in AdoNet (as both are written
well of course).
Cor
"dbuchanan" <db*********@hotmail.com> schreef in bericht
news:11**********************@g47g2000cwa.googlegr oups.com... Hello,
(Windows forms - SQL Server)
I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather than the key value that are stored in the table.
It works well if the comboboxes are selected when the row is created.
I fails to update the lookup table values if the combobox values are inserted at a later time or if the combobox selections are changed later.
The only work-around I know is to clear the form, datset, datagrid and reload everything.
Here is the stored procedure \\ CREATE PROCEDURE dbo.usp_047MSen_sel_ByDevi_TypeConnVolt ( @fkDevice char(36), @cmVarchar06 varchar(50) --pkComponentId for Cylinder )AS SET NOCOUNT ON; SELECT c.pkComponentId, c.fkDevice, c.fkComponentType, c.ComponentDescription, c.QuanSharingConfiguration, c.QuanConfigured,-- c.QuanActuations, c.cmVarchar01, c.cmVarchar02, c.cmVarchar03, c.cmVarchar04, c.cmVarchar05, c.cmVarchar06, c.cmNumeric01, c.cmNumeric02, c.cmNumeric03, c.cmNumeric04, c.cmNumeric05, c.cmNumeric06, c.cmNumeric07, c.cmBit01, c.cmBit02, c.cmBit03, c.cmBit04, c.cmBit05, c.cmBit06, c.cmBit07, c.cmBit08, c.cmBit09, c.cmBit10, c.cmBit11, c.cmSmallint01, v.Voltage, '<<from lookup table c.cmSmallint02, c.cmSmallint03, c.cmSmallint04, st.SensorType, '<<from lookup table c.cmSmallint05, sc.SensorConnection, '<<from lookup table c.cmUserNote, c.cmCreatedOn, c.cmCreatedBy, c.cmEditedOn, c.cmEditedBy, c.cmrowversion FROM tbl040Cmpt c left outer JOIN lkp104Voltage v ON c.cmSmallint01 = v.pkVoltageId left outer JOIN lkp302SensorType st ON c.cmSmallint04 = st.pkSensorTypeId left outer JOIN lkp103SensorConnection sc ON c.cmSmallint05 = sc.pkSensorConnectionId WHERE (c.fkDevice = @fkDevice) -- fkDevice = 'fc063d9f-62f1-4905-913a-e41f2471f2a7' AND c.cmVarchar06 = @cmVarchar06 -- pkComponentId - the -- AND c.cmVarchar06 = 'c6236862-dc3d-4e9d-a688-f57809fcb348' -- pkComponentId - the AND c.fkComponentType = 7 -- Motion Sensor ORDER BY c.ComponentDescription
GO //
Here is the example of the update code \\ Call UpdateSource2(dal.da040CmptFrm, "tbl040Cmpt") //
and
\\ Protected Sub UpdateSource2(ByVal dA As SqlDataAdapter, ByVal tbl As String)
Dim dsDataChanges As New CLIP.dsTables
dsDataChanges = CType(_dataSet1.GetChanges, CLIP.dsTables)
If (Not (dsDataChanges) Is Nothing) Then Try dA.Update(dsDataChanges, tbl)
_dataSet1.Merge(dsDataChanges) _dataSet1.AcceptChanges()
Catch ex As Exception MessageBox.Show("Exception Message: " & vbCrLf & ex.Message) MessageBox.Show("Exception Source: " & vbCrLf & ex.Source) MessageBox.Show("Exception StackTrace: " & vbCrLf & ex.StackTrace) End Try End If End Sub //
Is there a better way?
Thank you, dbuchanan
Hi,
"dbuchanan" <db*********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com... Hello,
(Windows forms - SQL Server)
I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather than the key value that are stored in the table.
It works well if the comboboxes are selected when the row is created.
I fails to update the lookup table values if the combobox values are inserted at a later time or if the combobox selections are changed later.
The only work-around I know is to clear the form, datset, datagrid and reload everything.
Here is the stored procedure \\ CREATE PROCEDURE dbo.usp_047MSen_sel_ByDevi_TypeConnVolt ( @fkDevice char(36), @cmVarchar06 varchar(50) --pkComponentId for Cylinder )AS SET NOCOUNT ON; SELECT c.pkComponentId, c.fkDevice, c.fkComponentType, c.ComponentDescription, c.QuanSharingConfiguration, c.QuanConfigured,-- c.QuanActuations, c.cmVarchar01, c.cmVarchar02, c.cmVarchar03, c.cmVarchar04, c.cmVarchar05, c.cmVarchar06, c.cmNumeric01, c.cmNumeric02, c.cmNumeric03, c.cmNumeric04, c.cmNumeric05, c.cmNumeric06, c.cmNumeric07, c.cmBit01, c.cmBit02, c.cmBit03, c.cmBit04, c.cmBit05, c.cmBit06, c.cmBit07, c.cmBit08, c.cmBit09, c.cmBit10, c.cmBit11, c.cmSmallint01, v.Voltage, '<<from lookup table c.cmSmallint02, c.cmSmallint03, c.cmSmallint04, st.SensorType, '<<from lookup table c.cmSmallint05, sc.SensorConnection, '<<from lookup table c.cmUserNote, c.cmCreatedOn, c.cmCreatedBy, c.cmEditedOn, c.cmEditedBy, c.cmrowversion FROM tbl040Cmpt c left outer JOIN lkp104Voltage v ON c.cmSmallint01 = v.pkVoltageId left outer JOIN lkp302SensorType st ON c.cmSmallint04 = st.pkSensorTypeId left outer JOIN lkp103SensorConnection sc ON c.cmSmallint05 = sc.pkSensorConnectionId WHERE (c.fkDevice = @fkDevice) -- fkDevice = 'fc063d9f-62f1-4905-913a-e41f2471f2a7' AND c.cmVarchar06 = @cmVarchar06 -- pkComponentId - the -- AND c.cmVarchar06 = 'c6236862-dc3d-4e9d-a688-f57809fcb348' -- pkComponentId - the AND c.fkComponentType = 7 -- Motion Sensor ORDER BY c.ComponentDescription
GO //
Here is the example of the update code \\ Call UpdateSource2(dal.da040CmptFrm, "tbl040Cmpt") //
and
\\ Protected Sub UpdateSource2(ByVal dA As SqlDataAdapter, ByVal tbl As String)
Dim dsDataChanges As New CLIP.dsTables
dsDataChanges = CType(_dataSet1.GetChanges, CLIP.dsTables)
If (Not (dsDataChanges) Is Nothing) Then Try dA.Update(dsDataChanges, tbl)
_dataSet1.Merge(dsDataChanges) _dataSet1.AcceptChanges()
Catch ex As Exception MessageBox.Show("Exception Message: " & vbCrLf & ex.Message) MessageBox.Show("Exception Source: " & vbCrLf & ex.Source) MessageBox.Show("Exception StackTrace: " & vbCrLf & ex.StackTrace) End Try End If End Sub //
Is there a better way?
From the sp i gathered you have following tables:
master: tbl040Cmpt (cmSmallint01, cmSmallint04, cmSmallint05)
lk1: kp104Voltage (pkVoltageId, Voltage)
lk2: lkp302SensorType (pkSensorTypeId, SensorType)
lk3: lkp103SensorConnection (pkSensorConnectionId, SensorConnection)
I'll show you how to do it for one lookup, you can do the same for the other
lookups. Instead of resolving foreign keys inside the stored procedure
using joins, you should only get the foreign keys and do the lookup using
relations and expression columns in .NET.
Fill DataSet with tbl040Cmpt and kp104Voltage:
DataSet ds = new DataSet();
tbl040CmptAdapter.Fill( ds, "tbl04Cmpt" ) ' no join query
kp104VoltageAdapter.Fill( ds, "kp104Voltage" )
Add relation between kp104Voltage(=parent) and tbl040Cmpt(=child):
ds.Relations.Add( "pk104Voltage_tbl04Cmpt", _
ds.Tables("kp104Voltage").Columns("pk104Voltage"), _
ds.Tables("tbl04Cmpt").Columns("cmSmallint01") )
Hide the foreign key column:
ds.Tables("tbl04Cmpt").Columns("cmSmallint01").Col umnMapping = _
MappingType.Hidden
Then add an expression column:
ds.Tables("tbl04Cmpt").Columns.Add( "Voltage", _
typeof(string), "Parent(pk104Voltage_tbl04Cmpt).Voltage" )
That's it, now you have a "Voltage" column (lookup,readonly) that will
change if the hidden cmSmallint01 field is changed.
There is however a bug with Updating DataTables that have expression
column(s), you need to remove the expression columns before and re-insert
them after a da.Update.
hth,
greetings
Thank you, dbuchanan
Bart,
Thank you so much for your reply and the tip on the bug too.
BTW 1: Is any there a bug list anywhere?
BTW 2: Do you know if this bug is fixed in .NET 2.0
--
dbuchanan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Vik |
last post by:
How can I display the lookup values in a datagrid?
E.g., the datagrid displays a table that contains a ProductID field. I want
to display a Product...
|
by: Jonathan Upright |
last post by:
Greetings to anyone who can help:
I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable
DataGrid" at the project selector screen. ...
|
by: Fred Nelson |
last post by:
Hi:
I have a VB.NET web app and in one section I'm creating a datagrid that
lists several id's and names - I would like to be able to send the...
|
by: dbuchanan |
last post by:
Hello,
For my datagrid I added a datagrid table style to include columns from
my lookup tables. These display the values in the lookup tables...
|
by: JohnSouth |
last post by:
Hi
I need a dropdown list column in a datagrid control, and I've got the
basics working where the column contents is text. However the data
table...
|
by: sierra467 |
last post by:
I realize that lookup fields in a table should not be used but that is
the way this particular creator has done. Could someone help me by...
|
by: Stephen Plotnick |
last post by:
I'm very new to VB.NET 2003
Here is what I have accomplished:
MainSelectForm - Selects an item
In a public class I pass a DataViewRow to
...
|
by: shookim |
last post by:
I don't care how one suggests I do it, but I've been searching for days
on how to implement this concept. I'm trying to use some kind of grid...
|
by: Just Me |
last post by:
Im struggling a bit with the update function.
I have bound a table with lets say 5 records ( 4 columns ) to the gridview ,
this displays jsut...
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: CD Tom |
last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
|
by: CD Tom |
last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
| |