public async insertData(data: any) {
const insertDataQuery = INSERT INTO farm_add ( officer_name, resolved_by, resolved_date, resolved_details, resolved_yn, visit_date, visit_purpose, visit_type ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
;
try {
const values:any = [
data.officer_name,
data.resolved_by,
data.resolved_date,
data.resolved_details,
data.resolved_yn ? 1 : 0,
data.visit_date,
data.visit_purpose,
data.visit_type
];
const result = await this.db.execute(insertDataQuery, values);
console.log('Insert result:', result);
} catch (error) {
console.error('Error inserting data:', error);
}
}
public async getAllData() { const getAllDataQuery = 'SELECT * FROM farm_add';
try {
const result = await this.db.query(getAllDataQuery, []);
if (result.values && result.values.length > 0) {
const data = result.values;
console.log(data);
return data;
} else {
console.error('Error retrieving data:', result);
return [];
}
} catch (error) {
console.error('Error executing query:', error);
return [];
}
}
i want to get he data but got null values
id : 2 officer_name : null resolved_by : null resolved_date : null resolved_details : null resolved_yn : null visit_date : null visit_purpose : null visit_type : null
inserting like this const yourData = { officer_name: "Ashwin", resolved_by: "yes", resolved_date: "2023-06-20", resolved_details: "Germination percentage was 90%.", resolved_yn: 1, visit_date: "2020-06-20", visit_purpose: "monitoring of rice planting.", visit_type: null, };
this.datasService.insertData(yourData)