samedi 20 juin 2015

fetch all column which equals my Email SqLlite

I want to fetch my all the column from table tblReg, It has column Registration,Name,Password,Email and Contact out which Email is checked while registration ,it is unique column.. value exist only once in table of one Email.

I am having login by matching Email with password and passing value of an email through intent in my home activity as KeyName Now i want to fetch all detail from SQLlite based on my Email,i am receiving from getExtra through Intent.

Here is my Code of Home Activity

public class activity_home extends Activity {
    DatabaseHandler dbh = new DatabaseHandler(this);
String regid,emailid,name,contact,data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity_home);
        TextView lblEmail = (TextView) findViewById(R.id.textView1);
        TextView lblReg = (TextView) findViewById(R.id.textView1);
        TextView lblName = (TextView) findViewById(R.id.textView1);
        dbh.open();
        try {
            data = getIntent().getExtras().getString("keyName");

            Cursor m1 = dbh.getRecord12(data);
            if (m1 != null) {
                m1.moveToFirst();
                name = m1.getString(m1.getColumnIndex("Name"));
                regid = m1.getString(m1.getColumnIndex("Registration"));
                contact = m1.getString(m1.getColumnIndex("Contact"));
                emailid = m1.getString(m1.getColumnIndex("Email"));
                m1.close();
            }

            if (!data.equals("")) {

                lblEmail.setText(Html.fromHtml("Email: <b>" + emailid + "</b>"));
                lblReg.setText(Html.fromHtml("Email: <b>" + regid + "</b>"));
                lblName.setText(Html.fromHtml("Email: <b>" + name + "</b>"));
            } else {
                Toast.makeText(getApplicationContext(), "Data Null Aya hai Bhai", Toast.LENGTH_SHORT).show();
            }
        }
        catch (Exception e)
        {
            String ex=e.toString();
            Toast.makeText(getApplicationContext(), ex, Toast.LENGTH_SHORT).show();
        }
            }

I have used a database handler class where i am using a query ,i think there is a problem in query please have a look in that ,i am sharing the cursor code only please correct me where i am wrong. Quick response will be appreciated and thanks in an advance.I am beginner in an android please help.

public Cursor getRecord12(String rowid) throws SQLiteException {
        String where = (KEY_EMAIL + "='" + rowid + "'") + " OR " + (KEY_NAME + "='" + rowid + "'");
        Cursor m = mDb.query(true, tblReg, new String[]{KEY_REGID, KEY_NAME, KEY_PASSWORD,KEY_EMAIL,KEY_MOBILENO}, where, null, null, null, null, null);
        if (m != null) {
            if(m.getCount()==0) {
                m=null;
            }
            else {
                m.moveToFirst();
            }
        }
        return m;
    }

Aucun commentaire:

Enregistrer un commentaire