-
-
Save kgrvamsi/6f4d7f3bce92d98bf49b6bfba31f1382 to your computer and use it in GitHub Desktop.
the demo of github.com/denisenkom/go-mssqldb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"fmt" | |
_ "github.com/denisenkom/go-mssqldb" | |
) | |
func main() { | |
DB, err := sql.Open("mssql", "server=172.16.32.1**;port=1433;user id=sa;password=*****;database=demo;") | |
count := 5 | |
sql := fmt.Sprintf("select top %d id,name from demo", count) | |
row, err := DB.Query(sql) | |
defer row.Close() | |
if err != nil { | |
fmt.Println(err) | |
} else { | |
for row.Next() { | |
var id int | |
var name string | |
row.Scan(&id, &name) | |
fmt.Print(id) | |
fmt.Println(name) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment