none
sqlite help RRS feed

  • Question

  • Hello I have taken data using sqlite how can I search in-data

    I have code like this, but datagridview also shows empty

               Dim cn As SQLiteConnection
    
                cn = myconnection
                cn.Open()
    
                Dim cm As SQLiteCommand = cn.CreateCommand()
    
                cm.CommandText = "SELECT * FROM Sheet1 WHERE Kurum LIKE @Kurum"
    
               cm.Parameters.AddWithValue("@Kurum", "%min")
    
                Dim reader As SQLiteDataReader = cm.ExecuteReader()
    
                While reader.Read
    
                    Debug.WriteLine(reader.GetString(1))
    
                End While




    • Edited by Hollowmana Thursday, June 27, 2019 9:54 AM
    Thursday, June 27, 2019 9:24 AM

All replies

  • Try using apostrophes cm.Parameters.AddWithValue("@Kurum", "'%min'") and if that does not work remove the WHERE condition to ensure data is being returned which can be done using reader.HasRows.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, June 27, 2019 10:22 AM
    Moderator
  • so how do I pass this constraint into datagridview

    Is there a different search method using parameters?

    • Edited by Hollowmana Thursday, June 27, 2019 10:33 AM
    Thursday, June 27, 2019 10:25 AM
  • so how do I pass this constraint into datagridview

    Is there a different search method using parameters?

    At this point the DataGridView is not part of this issue and not part of the original question, focus on reading data.

    What happens when using this?

    cm.CommandText = "SELECT * FROM Sheet1 WHERE Kurum LIKE @Kurum"
    cm.Parameters.AddWithValue("@Kurum", "'%min'") 

    Then 

    Dim reader As SQLiteDataReader = cm.ExecuteReader()
    If Reader.HasRows Then
     ...


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, June 27, 2019 10:58 AM
    Moderator
  • Hi,

    fill DataGridview:

        Dim constr As String = "xxxx"
        Dim conn As SqLiteConnection
        Dim sda As SqLiteDataAdapter
        Dim cmd As SqLiteCommand
        Dim dt As New DataTable
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using conn = New SqLiteConnection(constr)
                conn.Open()
                cmd = New SqLiteCommand("SELECT * FROM Sheet1 WHERE Kurum LIKE @Kurum", conn)
                cmd.Parameters.AddWithValue("@Kurum", "%min")
                sda = New SqLiteDataAdapter(cmd)
                sda.Fill(dt)
                DataGridview1.Datasource = dt
            End Using
        End Sub

    Best Regards,

    Alex



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 28, 2019 7:32 AM