Increment in Android SQLite - sqlite

I want to update the col_Item_Auto_ID column with +1 in each column
Like this: replace 10 with 11, 11 with 12, etc!!
Help me pls... here the code is,
public void updateMiddleTemp(int autoid) {
SQLiteDatabase db = this.getWritableDatabase();
int id=51;
ContentValues cv_temp1 = new ContentValues();
cv_temp1.put(col_Item_Auto_ID, col_Item_Auto_ID+1);
//ff
long stemp = db.updateWithOnConflict(Table_KOT_ITEMS_TEMP, cv_temp1,
col_Item_Auto_ID + " >= " + autoid, null,SQLiteDatabase.CONFLICT_IGNORE);
db.close();
}

Try this code, it works fine:
db.execSQL("UPDATE " + Table_KOT_ITEMS_TEMP + " SET "
+ col_Sl_No + " = " + col_Sl_No + " +1 WHERE "
+ col_Sl_No + " >" +into);
db.close();

You cannot do this with standard update method - you need to use execSql method instead:
String sql = "UPDATE " + Table_KOT_ITEMS_TEMP +
" SET " + col_Item_Auto_ID + "=" + col_ITEM_AUTO_ID + "+1" +
" WHERE " + col_ItemAutoID + " >= " + autoid;
db.execSql(sql);

This can be done with updateWithOnConflict().
The value provided for the value field in ContentValues is incorrect.
Resulting value should be "col_Item_Auto_ID + 1" and not "col_Item_Auto_ID1".
So try changing
cv_temp1.put(col_Item_Auto_ID, col_Item_Auto_ID+1);
to
cv_temp1.put(col_Item_Auto_ID, col_Item_Auto_ID+"+1");

This code worked for me:
String query = "UPDATE " + Constants.RecentChats.DB_RECENT_CHATS + " SET "
+ Constants.RecentChats.UNREAD_COUNT + " = "
+ Constants.RecentChats.UNREAD_COUNT +"+1"+ " WHERE "
+ Constants.RecentChats.JID + " =" + id;
db.execSQL(query);

Related

Asp.net , to_date Function

I want to update record in oracle db. But it gives me error "date format picture ends before converting..." I uses to_date function. datatype of column is DATE.
Here is my query
var updateddate = DateTime.Now;
var testing= this.hidvalue.Value;
var idrow = id.Text;
var anserrow = lblanswer.Text;
var weightpwd = lblweighted.Text;
var solvetimerow =lblsolvetime.Text;
var updatedby = Session["Name"];
string queryDuppass = "Update ADU.QAT_DATA set Question='" + idrow + "',Answer='" + anserrow + "', Question_Weighted='" + weightpwd + "', Resolve_Estimated_Time='" + solvetimerow + "', Updated_By='" + updatedby + "', Updated_Date= to_date('" + updateddate + "','mm-dd-yyyy hh12:mi:ss'" + ")" + " where ID='" + testing + "'";

Please Verify My ASP.NET Code to insert data to oracle database

No matter what I do the following code does not seem to work. It always breaks at ExecuteNonQuery().
Anything I am missiong?
Always throws
System.InvalidOperationException: 'Operation is not valid due to the current state of the object.'
protected void Submit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
OracleConnection conn = new OracleConnection(connectionString);
int room_id = Int32.Parse(DropDownList2.SelectedValue);
int activity_id = Int32.Parse(DropDownList1.SelectedValue);
string session_code = TextBox1.Text;
int start_time = GetTimeSeconds(startTime.Text);
int period = GetTimeSeconds(duration.Text);
string book_date = bookDate.Text;
string ref_no = DropDownList3.SelectedValue;
conn.Open();
using (OracleCommand cmd = new OracleCommand(
"insert into BRAZESH.ALL_SESSION(SESSION_CODE,START_TIME,\"PERIOD\",BOOKED_DATE,ROOM_ID,ACTIVITY_ID,REF_NO)" +
" values ('" + session_code + "'," + start_time + "," + period + ",to_date('" + book_date + "', 'yyyy-mm-dd')," + room_id + "," + activity_id + ", '" + ref_no + "')"))
{
try
{
cmd.ExecuteNonQuery();
}catch (OracleException ex)
{
throw ex;
}
}
}
}
You are not using conn while defining the connection to be used by the command. use the following line. Read details on usage here
using (OracleCommand cmd = new OracleCommand(
"insert into BRAZESH.ALL_SESSION(SESSION_CODE,START_TIME,\"PERIOD\",BOOKED_DATE,ROOM_ID,ACTIVITY_ID,REF_NO)" +
" values ('" + session_code + "'," + start_time + "," + period + ",to_date('" + book_date + "', 'yyyy-mm-dd')," + room_id + "," + activity_id + ", '" + ref_no + "')",conn))

incorrect syntax near the keyword 'Values'

this is my code.i want to save these values into database.And an error occured,
incorrect syntax near the keyword Values
foreach (GridViewRow gvr in GridView1.Rows)
{
string strcon1;
strcon1 = ConfigurationManager.ConnectionStrings["fwma_devConnectionString"].ConnectionString;
SqlConnection con1 = new SqlConnection(strcon1);
con1.Open();
SqlCommand com3 = new SqlCommand(strcon);
TextBox tb = (TextBox)gvr.FindControl("TextBox2");//value
string txt = tb.Text;
Label propertylabel = (Label)gvr.FindControl("Label4");//id-property
com3.CommandText = "INSERT INTO BrandProperties(PropertyID,BrandID,Values) values(" + propertylabel.Text + "," + B_id.Text + "," + tb.Text + " ), con1";
com3.Connection = con1;
com3.ExecuteNonQuery();
con1.Close();
use this
com3.CommandText = "INSERT INTO BrandProperties(PropertyID,BrandID,Values) values('" + propertylabel.Text + "','" + B_id.Text + "','" + tb.Text + "')";
instead of
com3.CommandText = "INSERT INTO BrandProperties(PropertyID,BrandID,Values) values(" + propertylabel.Text + "," + B_id.Text + "," + tb.Text + " ), con1";
If you are using the reserved keywords ,you should specify delimited identifiers either quoted or bracketed.
example using bracketed
com3.CommandText = "INSERT INTO BrandProperties(PropertyID,BrandID,[Values]) values(" + propertylabel.Text + "," + B_id.Text + "," + tb.Text + " ), con1";
Shouldn't this line be like this?
com3.CommandText = "INSERT INTO BrandProperties(PropertyID,BrandID,Values) values(" + propertylabel.Text + "," + B_id.Text + "," + tb.Text + ")";
and please use command parameters:
When should "SqlDbType" and "size" be used when adding SqlCommand Parameters?

Regarding word search and lucene.net c#

i will use lucene.net first time so couple of confusion arising in mind when see the line of code. i got a sample code for searching word with lucene and few line are not clear to me.here is sample code below.
Question 1
ListBox1.Items.Clear();
var searcher = new Lucene.Net.Search.IndexSearcher(MapPath("~/searchlucene/"));
var oParser = new Lucene.Net.QueryParsers.QueryParser("content", new StandardAnalyzer());
string sHeader = " OR (header:" + TextBox1.Text + ")";
string sType = " OR (type:" + TextBox1.Text + ")";
string sSearchQuery = "(" + TextBox1.Text + sHeader + sType + ")";
var oHitColl = searcher.Search(oParser.Parse(sSearchQuery));
for (int i = 0; i < oHitColl.Length(); i++)
{
Document oDoc = oHitColl.Doc(i);
ListBox1.Items.Add(new ListItem(oDoc.Get("header") + oDoc.Get("type") + oDoc.Get("content")));
}
searcher.Close();
Question 2
this below lines not clear what is going on...!! please discuss the objective of each line below.
string sHeader = " OR (header:" + TextBox1.Text + ")";
string sType = " OR (type:" + TextBox1.Text + ")";
string sSearchQuery = "(" + TextBox1.Text + sHeader + sType + ")";
var oHitColl = searcher.Search(oParser.Parse(sSearchQuery));
for (int i = 0; i < oHitColl.Length(); i++)
{
Document oDoc = oHitColl.Doc(i);
ListBox1.Items.Add(new ListItem(oDoc.Get("header") + oDoc.Get("type") + oDoc.Get("content")));
}
Question 3
what is header:
what is type:
why heade & type concatinated after search keyword like string
sSearchQuery = "(" + TextBox1.Text + sHeader + sType + ")";
Question 4
why content is missing in searchquery content
what would be the result if i write like
string sHeader = " OR (header:" + TextBox1.Text + ")";
string sType = " OR (type:" + TextBox1.Text + ")";
string sContent = " OR (content:" + TextBox1.Text + ")";
string sSearchQuery = "(" + TextBox1.Text + sHeader + sType + sContent ")";
why header, type & content is reading....what for??
*oDoc.Get("header") + oDoc.Get("type") + oDoc.Get("content")*
why i need to read header,type & content like
oDoc.Get("header") + oDoc.Get("type") + oDoc.Get("content")
we can read content only....why type & header is also required??
The first code builds a query that searches several fields, assuming that the input in TextBox1 does not mess with the query (like containing parentheses or whitespaces). Building a search query with string concatenation is often hard to get right, I would use the MultiFieldQueryParser instead.
var fields = new[] { "content", "header", "type" };
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
var queryParser = new MultiFieldQueryParser(Version.LUCENE_30, fields, analyzer);
var query = queryParser.Parse(TextBox1.Text);
var result = searcher.Search(query, 25); /* find 25 best matches */
Your for-loop iterates through the result and reads the values of the stored fields and add them to a listbox. This requires that the fields where indexed with Field.Store.YES to work.

How to connect mysql to DevExpress ASPxScheduler without SqlDataSource

I have an ASP.net project I'm looking at and they want to use MySQL. I'm used to SQL server but using mySQL shouldn't be a problem.
Normally the control would like a SqlDataSource to bind to but that's not available with MySQL (from other posts on this site).
What's the best way to connect MySQL and the DevExpress ASPxScheduler so that you can create appointments?
Why not an ObjectDataSource and write the data layer? Or use LLBLGen, I think it works just fine with MySQL. The one caveat I've seen is that the MySQL ODBC and ADO drivers have issues with metadata.
I did end up using the objectdatasource and the ObjectCreated method and wrote the datalayer to insert records into the mysql database. I've included my code just incase someone needs some help with some of the logic.
protected void appointmentsDataSource_ObjectCreated(object sender, ObjectDataSourceEventArgs e)
{
e.ObjectInstance = new CustomEventDataSource(GetCustomEvents());
}
public void InsertAppointment()
{
//need to reformat the dates
string tempStartDate;
string tempStartMinutes;
if (appointmentobject.Start.Minute.ToString().Length == 1)
{
tempStartMinutes = "0" + appointmentobject.Start.Minute.ToString();
}
else
{
tempStartMinutes = appointmentobject.Start.Minute.ToString();
}
tempStartDate = AppointmentObject.Start.Year + "-"
+ AppointmentObject.Start.Month + "-"
+ appointmentobject.Start.Day + " "
+ appointmentobject.Start.Hour + ":"
+ tempStartMinutes;
string tempEndDate;
string tempEndMinutes;
if (appointmentobject.End.Minute.ToString().Length == 1)
{
tempEndMinutes = "0" + appointmentobject.End.Minute.ToString();
}
else
{
tempEndMinutes = appointmentobject.End.Minute.ToString();
}
tempEndDate = AppointmentObject.End.Year + "-"
+ AppointmentObject.End.Month + "-"
+ appointmentobject.End.Day + " "
+ appointmentobject.End.Hour + ":"
+ tempEndMinutes;
//TODO Add CustomField : Need to add to this Insert Statement
//Change the appointment subject
string NewSubject = AppointmentObject.CustomFields["fldFirstName"]
+ ", " + AppointmentObject.CustomFields["fldLastName"]
+ ", " + AppointmentObject.CustomFields["fldClassID"]
+ ", " + AppointmentObject.CustomFields["fldPhoneNumberDay"];
string mySQLQueryString = #"INSERT INTO appointment (StartDate,EndDate,Subject,Status,Description,label,location,Type,FirstName,
LastName,PhoneNumberDay,PhoneNumberEvening,DriversLicenseNumber,Email,RentalCar,Payment,ConfirmationNumber,
PermitNumber,ClassID,CreateDate,CreateUser,NoticeToReport)
VALUES('" + tempStartDate + "','"
+ tempEndDate + "', '"
//+ AppointmentObject.Subject + "',"
+ NewSubject + "',"
+ AppointmentObject.StatusId + ",'"
+ AppointmentObject.Description + "',"
+ AppointmentObject.LabelId + ", '"
+ AppointmentObject.Location + "',"
+ "0, '" //type
+ AppointmentObject.CustomFields["fldFirstName"] + "','"
+ AppointmentObject.CustomFields["fldLastName"] + "','"
+ AppointmentObject.CustomFields["fldPhoneNumberDay"] + "','"
+ AppointmentObject.CustomFields["fldPhoneNumberEvening"] + "','"
+ AppointmentObject.CustomFields["fldDriversLicenseNumber"] + "','"
+ AppointmentObject.CustomFields["fldEmail"] + "',"
+ AppointmentObject.CustomFields["fldRentalCar"] + ","
+ AppointmentObject.CustomFields["fldPayment"] + ",'"
+ AppointmentObject.CustomFields["fldConfirmationNumber"] + "','"
+ AppointmentObject.CustomFields["fldPermitNumber"] + "',"
+ AppointmentObject.CustomFields["fldClassID"] + ", '"
//ignore create date for now.
//+ AppointmentObject.CustomFields["fldCreateDate"] + "', '"
+ "2009-01-01 12:00', '"
+ AppointmentObject.CustomFields["fldCreateUser"] + "', "
+ AppointmentObject.CustomFields["fldNoticeToReport"] + ")";
MySqlConnections test = new MySqlConnections();
test.InsertRow(mySQLQueryString);
}
public class MySqlConnections
{
private static string DriverConnectionString = "Database=driverexam;Data Source=localhost;User Id=ART;Password=art01";
public DataSet SelectRows(DataSet dataset, string query, string tablename)
{
MySqlConnection conn = new MySqlConnection(DriverConnectionString);
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = new MySqlCommand(query, conn);
adapter.Fill(dataset, tablename);
conn.Close();
return dataset;
}
public bool InsertRow(string query)
{
// MySqlConnection conn = new MySqlConnection(DriverConnectionString);
MySqlConnection conn = new MySqlConnection();
MySqlCommand cmd = new MySqlCommand();
conn.ConnectionString = DriverConnectionString;
try
{
conn.Open();
cmd.Connection = conn;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
conn.Close();
Console.WriteLine("Success Occurred ");
} //end of try
catch(Exception ex)
{
Console.WriteLine("Error Occurred - " + ex.Message);
}
return true;
}
}

Resources