How to connect Flutter app to SQL Server to send queries
469
You can do so by using https://github.com/nippur72/SqlServerSocket
However, you need to install the SqlServerSocket on the server machine where SQL Server is installed.
// creates a connection
var conn = new SqlConnection("SERVER=localhost;Database=mydb;Trusted_connection=yes");
// open connection
await conn.open();
// runs a query returning a single value
var howmany = await conn.queryValue("SELECT COUNT(*) FROM Customers");
// runs a query returning a single row
var myFirstCustomer = await conn.querySingle("SELECT name,age FROM Custormers");
print(myFirstCustomer["name"]);
// runs a query returning all rows
var customers = await conn.query("SELECT TOP 10 name,age FROM Custormers");
for(var customer in customers)
{
print(customer["name"]);
}
// execute a command, returning the number of rows affected
var n = await conn.execute("UPDATE Customers SET age=0");
print("zeroed $n customers");
// disconnect
await conn.close();
Author by
Smith
Updated on December 14, 2022Comments
-
Smith 11 months
I created an application with a table, which should be filled by using queries to the SQL SERVER. How can I use the application to send requests to the server?
-
Smith about 4 yearsI already tried this method, It's not worked.