Showing posts with label idictionary. Show all posts
Showing posts with label idictionary. Show all posts

Monday, February 20, 2012

Problem inserting data from IDictionary into Sql2005

Hi,

I'm not sure if this should be in the Sql or VB forums.

Using VS2005 I have a graphics program which holds data in a Dictionary Object.

The data consists of a Key and a Structure called Arrows. This structure holds a startpoint and an endpoint, both of which consist of x and y co-ordinates. I need to insert these four co-ordinates into X,Y,X1 and Y1 columns of a table,

The following Insert statement will insert the correct IdKey and Textbox data, but will not compile the co-ordinates.

I have initialised the Points of the structure, but get the error message that Type is not defined.

With dbCommand

Dim _mstartPoint As Point

Dim _mendPoint As Point

Dim strSql As String

For Each kvp As KeyValuePair(Of String, Arrow) In Arrows

strSql = "INSERT INTO Drawing_Arrows (ArrowId,FlashingCode,X1,Y1,X2,Y2) Values ('" & kvp.Key & "', '" & txt_Title.Text & "','" & CType(Arrows(kvp.Key), _mstartPoint).x.ToString & "', '" & CType(Arrows(kvp.Key), _mstartPoint).y.ToString & "''" & CType(Arrows(kvp.Key), _mendPoint).x.ToString & "', '" & CType(Arrows(kvp.Key), _mendPoint).y.ToString & "')"

.CommandText = strSql

.CommandType = Data.CommandType.Text

.Connection = dbConnection

.ExecuteNonQuery()

Next

End With

My problem is how to extract the _mstartPoint x and _mstartPoint y as seperate items for insertion into X and Y in the table.

Any suggestions welcome.

Tailor

Hi,

Finally figured out the way to do answer this question. use IDictionaryEnumerator. Code as shown, works.

Dim arrowEnumerator As IDictionaryEnumerator = Arrows.GetEnumerator

Do While arrowEnumerator.MoveNext

strSql = "INSERT INTO Drawing_Arrows (ArrowId,FlashingCode,X1,Y1,X2,Y2) Values ('" & _uniqueID & "','" & txt_Title.Text & "','" & CType(arrowEnumerator.Value, Arrow).StartPoint.X.ToString & "', '" & CType(arrowEnumerator.Value, Arrow).StartPoint.Y.ToString & "', '" & CType(arrowEnumerator.Value, Arrow).EndPoint.X.ToString & "', '" & CType(arrowEnumerator.Value, Arrow).EndPoint.Y.ToString & "')"

.CommandText = strSql

.CommandType = Data.CommandType.Text

.Connection = dbConnection

.ExecuteNonQuery()

Loop

Probably no use to anyone else, but posted it in case.

Tailor