This is a creation in Article, where the information may have evolved or changed.
Err = rows. Scan (&user. Id,&user. Name)
If err! = Nil {
Fmt. PRINTLN (ERR)
}
Fmt. Println ("Content:", user)
Error during query:
sql:expected destination arguments in Scan, not 2
Reason for the occurrence:
Database is not more than two fields, and you only get 2 fields, so an error
Workaround 1:
Err = rows. Scan (&user. Id,&user. Name,&user ...) Get it all.
Solution 2:
Rows, err: = db. Query (data)//fmt. PRINTLN (db) if err! = Nil {log. Fatalln (Err)}//field cols, _: = Rows. Columns () for I: = range cols {fmt. Print (Cols[i]) fmt. Print ("\ t")}//fmt. Println ("")//fmt. Println ("=================================")//values: = Make ([]sql. Rawbytes, Len (cols))//scans: = Make ([]interface{}, Len (cols))////for I: = range values {////scans[i] = &values[i]//// }////results: = Make (map[int]map[string]string)////i: = 0////for rows. Next () {////if err: = rows. Scan (Scans ...); Err! = Nil {////fmt. Println ("Error")////return////}////row: = Make (map[string]string)////for J, V: = Range values {////key: = Cols[j]////row [Key] = string (v)////}////results[i] = row////i++////}//////Print result////for i, M: = Range Results {////fmt. Println (i)////for k, V: = range m {////fmt. Println (k, ":", v)////}////fmt. Println ("========================")////}