I have a django project that is connected to  MS SQL using **pyodbc**.

I am able to connect  and retrieve data.

But the problem is when i tried to filter the data on multiple fields using 
**WHERE & LIKE** the system crash crash and display the below error.

> 'tuple' object has no attribute 'format'

views.py
====

    from django.shortcuts import render
    import pyodbc
    
    
    def connect(request):
    
        conn = pyodbc.connect(
            'Driver={ODBC Driver 17 for SQL Server};'
            'Server=DESKTOP-LPD1575\\SQLEXPRESS;'
            'Database=testDB;'
            'UID=test;'
            'PWD=test;'
    
        )
        query = 'n'
        queryid = 3
        cursor = conn.cursor()
       
        c = cursor.execute('SELECT * FROM Artist where artistName like  ? 
or id = ?',('%{0}%','{1}').format(query,queryid))
       
        print(c)
        return render (request,'connect.html',{"c":c})

connect.html
==============

    <table align = "center">
    <tr align="center">
                <th>id</th>
                <th>FolderNumber</th>
                <th>Folderdate</th>
               
            </tr>
    {% for row in c %}
     <tr align="center">
        <td>{{ row.0 }}</td>
        <td>{{ row.1 }}</td>
        <td>{{ row.2 }}</td>
        
    </tr>
    {% endfor %}
    </table>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0913c12c-942b-472f-bc77-33f4b576235a%40googlegroups.com.

Reply via email to