Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
5
Answers
problem in insert into sqlite db ?
ghasem deh
8y
716
1
Reply
hi guy's
when try insert new data in database send this error : "attached database stopped"
this database class :
public
boolean
insertUser(String userName,
int
age,
int
gender,
int
password, String memDescription, String pic) {
User user =
null
;
openDatabase();
db.beginTransaction();
try
{
ContentValues values =
new
ContentValues();
values.put(
"userName"
, user.getUserName());
values.put(
"age"
, user.getAge());
values.put(
"gender"
, user.getGender());
values.put(
"password"
, user.getPassword());
values.put(
"memDescription"
, user.getMemDescription());
values.put(
"pic"
, user.getPic());
long
result = db.insertOrThrow(
"tblUsers"
,
null
, values);
db.setTransactionSuccessful();
closeDatabase();
if
(result == -
1
)
return
false
;
else
return
true
;
}
catch
(Exception e) {
e.printStackTrace();
Log.d(TAG,
"???? ??? ?? ???????"
);
return
false
;
}
finally
{
db.endTransaction();
closeDatabase();
}
}
this in activity :
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(
new
View.OnClickListener() {
@Override
public
void
onClick(View view) {
try
{
boolean
isInserted = DB_HELPER.insertUser(EDT_NAME.getText().toString(), Integer.parseInt(EDT_AGE.getText().toString()),
Integer.parseInt(EDT_GENDER.getText().toString()), Integer.parseInt(EDT_PASS.getText().toString()),
EDT_DESC.getText().toString(), EDT_PIC.getText().toString());
if
(isInserted ==
true
)
startActivity(
new
Intent(AddActivity.
this
, MainActivity.
class
));
else
Snackbar.make(view,
"??? ?? ??? ????? ????!"
, Snackbar.LENGTH_LONG).setAction(
"Action"
,
null
).show();
}
catch
(Exception e){
e.printStackTrace();
return
;
}
}
});
and this user table class :
public
class
User {
private
int
id;
private
String userName;
private
int
age;
private
int
gender;
private
int
password;
private
String memDescription;
private
String pic;
public
User(
int
id, String userName,
int
age,
int
gender,
int
password, String memDescription, String pic) {
this
.id = id;
this
.userName = userName;
this
.age = age;
this
.gender = gender;
this
.password = password;
this
.memDescription = memDescription;
this
.pic = pic;
}
public
int
getId() {
return
id;
}
public
void
setId(
int
id) {
this
.id = id;
}
public
String getUserName() {
return
userName;
}
public
void
setUserName(String userName) {
this
.userName = userName;
}
public
int
getAge() {
return
age;
}
public
void
setAge(
int
age) {
this
.age = age;
}
public
int
getGender() {
return
gender;
}
public
void
setGender(
int
gender) {
this
.gender = gender;
}
public
int
getPassword() {
return
password;
}
public
void
setPassword(
int
password) {
this
.password = password;
}
public
String getMemDescription() {
return
memDescription;
}
public
void
setMemDescription(String memDescription) {
this
.memDescription = memDescription;
}
public
String getPic() {
return
pic;
}
public
void
setPic(String pic) {
this
.pic = pic;
}
}
Post
Reset
Cancel
Answers (
5
)
Next Recommended Forum
Android Emulator running 5.1 crashes at boot
Realtime Time Application