大家好,对于这部分节目,它基本上是折纸艺术家的画廊,可以观看其他艺术家设计的现有折痕图案。我有程序显示艺术家姓名,难度,主题和模型名称,但我也希望它在datagridview中显示特定折纸模型的折痕图案的图像。我将所有图像都保存在我的笔记本电脑上并且我已经搜索了很多但是还没有找到解决方案。我已经尝试了Datagridviewimage列,但它出现了错误以及Datagridview单元格格式。 Here is a pic of the window
这是我的代码:
公共班级画廊 昏暗的SQl作为新的SQLControl
Private Sub Gallery_Shown(sender As Object, e As EventArgs) Handles Me.Shown
LoadGrid()
GetArtists()
GetDifficulties()
GetTheme()
End Sub
Private Sub LoadGrid()
SQl.ExecQuery("SELECT ArtistName, Difficulty, Theme, ModelName, CreasePattern " &
"FROM GalleryTB " &
"ORDER BY ArtistName ASC, ModelName ASC ")
If String.IsNullOrEmpty(SQl.Exception) Then GalleryResult.DataSource = SQl.SQLDS.Tables(0)
End Sub
Private Sub ModelSearch(ModelName As String)
SQl.AddParam("@ModelName", "%" & ModelName & "%")
SQl.ExecQuery("SELECT ArtistName, Difficulty, Theme, ModelName, CreasePattern " &
"FROM GalleryTB " &
"WHERE ModelName LIKE @ModelName " &
"ORDER BY ArtistName ASC, ModelName ASC ")
If Not String.IsNullOrEmpty(SQl.Exception) Then MsgBox(SQl.Exception) : Exit Sub
GalleryResult.DataSource = SQl.SQLDS.Tables(0)
End Sub
Private Sub ArtistSearch(ArtistName As String)
SQl.AddParam("@ArtistName", "%" & ArtistName & "%")
SQl.ExecQuery("SELECT ArtistName, Difficulty, Theme, ModelName, CreasePattern " &
"FROM GalleryTB " &
"WHERE ArtistName LIKE @ArtistName " &
"ORDER BY ArtistName ASC, ModelName ASC ")
If Not String.IsNullOrEmpty(SQl.Exception) Then MsgBox(SQl.Exception) : Exit Sub
GalleryResult.DataSource = SQl.SQLDS.Tables(0)
End Sub
Private Sub DifficultySearch(Difficulty As String)
SQl.AddParam("@Difficulty", "%" & Difficulty & "%")
SQl.ExecQuery("SELECT ArtistName, Difficulty, Theme, ModelName, CreasePattern " &
"FROM GalleryTB " &
"WHERE Difficulty LIKE @Difficulty " &
"ORDER BY ArtistName ASC, ModelName ASC ")
If Not String.IsNullOrEmpty(SQl.Exception) Then MsgBox(SQl.Exception) : Exit Sub
GalleryResult.DataSource = SQl.SQLDS.Tables(0)
End Sub
Private Sub ThemeSearch(Theme As String)
SQl.AddParam("@Theme", "%" & Theme & "%")
SQl.ExecQuery("SELECT ArtistName, Difficulty, Theme, ModelName, CreasePattern " &
"FROM GalleryTB " &
"WHERE Theme LIKE @Theme " &
"ORDER BY ArtistName ASC, ModelName ASC ")
If Not String.IsNullOrEmpty(SQl.Exception) Then MsgBox(SQl.Exception) : Exit Sub
GalleryResult.DataSource = SQl.SQLDS.Tables(0)
End Sub
Private Sub SearchBt_Click(sender As Object, e As EventArgs) Handles SearchBt.Click
ModelSearch(ModelNameTxt.Text)
End Sub
Private Sub ArtistNameBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ArtistNameBox.SelectedIndexChanged
ArtistSearch(ArtistNameBox.Text)
End Sub
Private Sub DifficultyBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DifficultyBox.SelectedIndexChanged
DifficultySearch(DifficultyBox.Text)
End Sub
Private Sub ThemeBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ThemeBox.SelectedIndexChanged
ThemeSearch(ThemeBox.Text)
End Sub
Private Sub GetArtists()
SQl.ExecQuery("SELECT DISTINCT ArtistName " &
"FROM GalleryTB " &
"ORDER BY ArtistName ASC ")
If String.IsNullOrEmpty(SQl.Exception) Then
For Each dr As DataRow In SQl.SQLDS.Tables(0).Rows
ArtistNameBox.Items.Add(dr("ArtistName").ToString)
Next
End If
End Sub
Private Sub GetDifficulties()
SQl.ExecQuery("SELECT DISTINCT Difficulty " &
"FROM GalleryTB " &
"ORDER BY Difficulty ASC ")
If String.IsNullOrEmpty(SQl.Exception) Then
For Each dr As DataRow In SQl.SQLDS.Tables(0).Rows
DifficultyBox.Items.Add(dr("Difficulty").ToString)
Next
End If
End Sub
Private Sub GetTheme()
SQl.ExecQuery("SELECT DISTINCT Theme " &
"FROM GalleryTB " &
"ORDER BY Theme ASC ")
If String.IsNullOrEmpty(SQl.Exception) Then
For Each dr As DataRow In SQl.SQLDS.Tables(0).Rows
ThemeBox.Items.Add(dr("Theme").ToString)
Next
End If
End Sub
Private Sub BackToMainmenuBT_Click(sender As Object, e As EventArgs) Handles BackToMainmenuBT.Click
Me.Close()
Mainmenu.Show()
End Sub
Private Sub GalleryResult_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles GalleryResult.CellFormatting
If GalleryResult.Rows.Count > 0 Then
Dim Link = GalleryResult.Rows(e.RowIndex).Cells(3).Value
If Link.ToString.Contains("Ryujin 3.5") Then
GalleryResult.Rows(e.RowIndex).Cells(4).Value = Image.FromFile("C:\Users\Suraj_2\Downloads\Pictures\Origami\Ryujin 3.5 CP.jpg")
End If
End If
End Sub
结束班
导入System.Data.SqlClient 公共类SQLControl '私有SQLCon为新的SqlConnection {.ConnectionString =" Server =(localdb)\ Projects; Database = GalleryDB"} 私有SQLCon为新的SqlConnection {.ConnectionString =" Server =(localdb)\ MSSQLLocalDB; Database = GalleryDB"} 私有SQlCmd作为SqlCommand
Public SQLDA As SqlDataAdapter
Public SQLDS As DataSet
Public Params As New List(Of SqlParameter)
Public RecordCount As Integer
Public Exception As String
Public Sub ExecQuery(Query As String)
RecordCount = 0
Exception = ""
Try
SQLCon.Open()
SQlCmd = New SqlCommand(Query, SQLCon)
Params.ForEach(Sub(p) SQlCmd.Parameters.Add(p))
Params.Clear()
SQLDS = New DataSet
SQLDA = New SqlDataAdapter(SQlCmd)
RecordCount = SQLDA.Fill(SQLDS)
SQLCon.Close()
Catch ex As Exception
Exception = ex.Message
End Try
If SQLCon.State = ConnectionState.Open Then SQLCon.Close()
End Sub
Public Sub AddParam(Name As String, Value As Object)
Dim NewParam As New SqlParameter(Name, Value)
Params.Add(NewParam)
End Sub
结束课程 编辑*** Error message [表] [3]
谢谢, Mistry27