Skip to content

When Querying Tally ERP Through ODBC Certain Fields Cause A Wrong Column Error #200

@azwalzaman

Description

@azwalzaman

So this works perfectly for most queries with Tally but for certain fields I get this error wrong column #0 length 0 returned, 8 expected. Same code works for say SELECT $Name FROM StockItem and the query that causes errors here works fine with PyODBC. Any idea what I can do for this? The value of the field when extracted through PyODBC is a string of the form Price/Unit for example 99.00/nos

import (
	"database/sql"
	"fmt"
	"log"
)

func ReadProducts(db *sql.DB) {
	rows, err := db.Query("SELECT $StandardPrice FROM StockItem")
	if err != nil {
		log.Fatal("Failed to execute query:", err)
	}
	defer rows.Close()

	for rows.Next() {
		var stockItemName sql.NullString

		err := rows.Scan(&stockItemName)
		if err != nil {
			log.Fatal("Failed to scan row:", err)
		}

		fmt.Printf("Stock Item Name: %s\n", stockItemName.String)
	}

	if err = rows.Err(); err != nil {
		log.Fatal("Error occurred during row iteration:", err)
	}
}

Code for the connection

import (
	"database/sql"

	_ "github.com/alexbrainman/odbc"
)

func GetTallyConnection() (*sql.DB, error) {
	connStr := "DSN=TallyODBC64_9000;DRIVER=Tally ODBC DRIVER64;Server=localhost;Port=9000;"

	db, err := sql.Open("odbc", connStr)
	if err != nil {
		return nil, err
	}

	return db, nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions