DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.sqlite"); using (DbConnection conn = fact.CreateConnection()) { conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["sqliteConnString"].ConnectionString; conn.Open(); DbCommand comm = conn.CreateCommand(); comm.CommandText = "select * from role"; comm.CommandType = CommandType.Text; using (IDataReader reader = comm.ExecuteReader()) { while (reader.Read()) { Response.Write(reader["rName"]); } } } <connectionStrings> <add name="sqliteConnString" connectionString="Data Source=C:\ys_sqlite.db3;Pooling=true;FailIfMissing=false" providerName="System.Data.sqlite" /> </connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0"/> <requiredRuntime version="v4.0.20506" /> </startup>
App.config or web.config 中,针对.net 不同版本需要加上!
原文链接:https://www.f2er.com/sqlite/202364.html