Answer the question
In order to leave comments, you need to log in
How to fix "No connection associated with this command" error?
SQLiteConnection connect = new SQLiteConnection("Data Source=base.db;");
connect.Open();
SQLiteCommand command = new SQLiteCommand(@"UPDATE voices SET pass = '" + pass +
"', hash = '" + hash +
"' WHERE id = '" + id + "'");
command.ExecuteNonQuery();
connect.Close();
Answer the question
In order to leave comments, you need to log in
Well, that's logical. Connection in itself, command - in itself.
If you just look at the description of SqlCommand (architecture for SQLite is the same) https://msdn.microsoft.com/en-us/library/system.da...
then you can see the following:
using (SqlConnection conn = new SqlConnection(connectionString)) {
using (SqlCommand cmd = new SqlCommand(commandText, conn)) {
// There're three command types: StoredProcedure, Text, TableDirect. The TableDirect
// type is only for OLE DB.
cmd.CommandType = commandType;
cmd.Parameters.AddRange(parameters);
conn.Open();
return cmd.ExecuteNonQuery();
}
}
public void ReadMyData(string myConnString)
{
string mySelectQuery = "SELECT DeptNo, DName FROM Dept";
SQLiteConnection sqConnection = new SQLiteConnection(myConnString);
SQLiteCommand sqCommand = new SQLiteCommand(mySelectQuery,sqConnection); // команда конструируется с указанием соединения!!!
sqConnection.Open();
SQLiteDataReader sqReader = sqCommand.ExecuteReader();
try
{
while (sqReader.Read())
{
Console.WriteLine(sqReader.GetInt32(0).ToString() + ", " + sqReader.GetString(1));
}
}
finally
{
// always call Close when done reading.
sqReader.Close();
// always call Close when done reading.
sqConnection.Close();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question