英文:
How to use the Scan method
问题
我必须使用scan
方法来获取并存储我的ID,但程序无法编译。
第一次尝试:
query := "INSERT INTO " + table + "(" + removeLastRune(columns) + ") VALUES (" + removeLastRune(values) + ") RETURNING id".scan(&id)
id".scan未定义(未命名类型字符串没有scan字段或方法)
然后我按照文档进行了尝试,但是没有效果...
query := db.QueryRow("INSERT INTO " + table + "(" + removeLastRune(columns) + ") VALUES (" + removeLastRune(values) + ") RETURNING id").scan(&id)
scan未定义(*sql.Row类型没有scan字段或方法,但有Scan)
对问题有什么想法吗?
英文:
I have to use the scan method for get en store my id but the program does not want to compile.
The first time I tried:
query := "INSERT INTO " + table + "(" + removeLastRune(columns) + ") VALUES (" + removeLastRune(values) + ") RETURNING id".scan(&id)
> id".scan undefined (type untyped string has no field or method scan)
Then I apply the documentation but nothing...
query := db.QueryRow("INSERT INTO " + table + "(" + removeLastRune(columns) + ") VALUES (" + removeLastRune(values) + ") RETURNING id").scan(&id)
> scan undefined (type *sql.Row has no field or method scan, but does have Scan)
An idea of the problem?
答案1
得分: 1
只需阅读错误消息:
> scan未定义(类型*sql.Row没有scan字段或方法,但有Scan)
scan
未定义,但Scan
是存在的。在您的第二个示例中,将.scan
替换为.Scan
。
英文:
Just read the error message:
> scan undefined (type *sql.Row has no field or method scan, but does
> have Scan)
scan
is undefined but Scan
is not. Replace .scan
by .Scan
in your second example
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论