TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ram Prasad
NA
326
18.4k
Compare data with the SQLite database
Jan 20 2021 6:17 AM
Compare data with the SQLite database, display the output if data exist in database and insert in database if does not exist in database
I am getting a string of words as output in `returnValue` which I want to compare to a SQLite database. If the value of `returnValue` exists and starts with the letter 'k' in the database then output gets displayed. If `returnValue` starts with the letter 'k' and does not exist in database then it gets added into the database. Any other string starting with any other letter does not do anything.
For example, assuming 'Kevin' already exists in the database, if the output in `returnValue` is Kevin then Kevin must show in `Console.Write`. If output in `returnValue` is 'Kelly' (which does not exist in the database) then it gets added into the database. If the output of `returnValue` is 'John', nothing happens.
I tried the following code, but it is not working.
string
returnValue =
string
.Join(
""
, dataResult.ToArray());
Database databaseObject =
new
Database();
databaseObject.OpenConnection();
SQLiteCommand cmd =
new
SQLiteCommand();
SQLiteDataReader dataReader;
if
(returnValue.StartsWith(
'k'
))
{
string
value = cmd.ExecuteScalar()
as
string
;
if
(returnValue.Equals(value))
{
databaseObject.OpenConnection();
using
(cmd =
new
SQLiteCommand(
"SELECT * FROM k"
, databaseObject.myConnection))
{
dataReader = cmd.ExecuteReader();
while
(dataReader.Read())
{
Console.Write(Data);
}
}
}
else
{
query =
"INSERT INTO k ('Data') VALUES (@Data)"
;
cmd.CommandText = query;
cmd.Parameters.AddWithValue(
"@Data"
, returnValue);
}
databaseObject.CloseConnection();
}
else
{
return
;
}
Reply
Answers (
4
)
Dataset table rows
when build project error manifest display why and how to solve issue ?