When Querying Tally ERP Through ODBC Certain Fields Cause A Wrong Column Error
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
}
No idea.
I used this driver to connect to MS SQL Server. Never to TallyODBC64_9000 . Maybe you can adjust the code so it works with TallyODBC64_9000 .
Alex
No idea.
I used this driver to connect to MS SQL Server. Never to TallyODBC64_9000 . Maybe you can adjust the code so it works with TallyODBC64_9000 .
Alex
Yeah, fair. I was considering it already actually but I wanted to see if you have any idea of what it could be first. Also I just realized I forgot to change some of the variable names. I was playing around with the fields a bit to see what was causing the issue haha
I was considering it already actually but I wanted to see if you have any idea of what it could be first.
No idea. But all source code is there.
Alex
@azwalzaman Facing same issue while fetching form Tally, string type fields works fine but number like $OpeningBalance, $ClosingBlance throws runtime error "wrong column #0 length 0 returned, 8 expected". Any luck? Might be $ with number could be issue, just throwing an idea