Hi Experts,
How to save Ultragrid Layout in SQL Server?
Pl s help me.
You could use a varbinary or an xml column to save the layout. The display layout property of the grid has 2 methods
1°: ultragrid.DisplayLayout.Save(Stream); 2°: ultragrid.DisplayLayout.SaveAsXml(Stream);
1° method: you have to save it on a varbinary column. i would use this one. A varbinary column is an array of byte so the stream must be converted to a byte array before saving into the column!
2° method: you have to save the data on a xml column. So first, the stream must be convertet into xml and than saved on the column.
hope it helps.
Here's a KB article that may help:
HOWTO:How can I save a stream to a database?
Thanks for the answer, Mike.
I knew I could just do it with XML but also know that Binary would be faster... It is such a small difference that 'at the end of the day' it really shouldn't noticeably matter. I just thought it was weird that it all works until loading the retrieved data from the database (since I have already coded it and that was the final step ... I might add my first reaction wasn't to notice it was weird). I suspect that there is a setting on the SQL Server as to how it stores the binary data that may 'fix' it... on the other hand, it needs to be done yesterday :)
If you do find any insight on how to do this in binary format, let us know.
Again, thanks.
Mitch
I've never tried doing this in Binary, I think you might have to save and load as XML.
Also, the sample code in the KB article might be out of date. Here's a link to a thread where I posted some sample code that works:
Convert String to Stream correctly for DisplayLayout.Load() - Infragistics Community
No problem saving it to the database as varbinary but retrieving and loading it I get an 'Illegal characters in encoding.' error. I looked at the array values and the sixth one is 255 and that is throwing the error. Do I have to do something special to the byte array I am saving to the SQL Server to make it ascii?
Here is my code for retrieving. I embed a call to this in the displaylayout.load method of the grid as the Memory stream parameter:
Friend Function getUserGridSettingsStream(ByVal gridname As String) As MemoryStream
Dim bSettings As Byte() = Nothing
Dim cmd As SqlCommand = Nothing
Dim DbConn As SqlConnection = New SqlConnection(SQLConnStr)
Select Case gridname
Case "uwgProductionGrid"
cmd = New SqlCommand("usp_GetProductionGridSettings", DbConn)
Case "AdminMaster"
cmd = New SqlCommand("usp_GetAdminMasterGridSettings", DbConn)
End Select
Dim UserID As SqlParameter = cmd.Parameters.Add("@UserID", SqlDbType.NVarChar)
Try
DbConn.Open()
UserID.Value = cApp.UserID
cmd.CommandType = CommandType.StoredProcedure
'this works fine
bSettings = DirectCast(cmd.ExecuteScalar(), Byte())
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If DbConn.State = ConnectionState.Open Then
DbConn.Close()
End If
End Try
Dim gridSettingsStream = New MemoryStream(bSettings)
gridSettingsStream.Seek(0, IO.SeekOrigin.Begin)
'when I pass this stream into the displaylayout method I get the error about illegal characters.
Return gridSettingsStream
End Function