Displaying Query data in a TextInput Field in Flex? - database

I'm trying to display query data into multiple TextInput Fields in Flex.
<mx:TextInput id="stagInput" text="{acContacts}" width="170" x="120" y="74"/>
This is what I'm trying but all that displays is [object Object]
I think I need to define the database field I'm wanting to display, but I'm unsure how to do this as TextInput fields don't support dataField or labelField properties. Is there another property I don't know about?
How do i go about fixing this?
Thanks!

Is acContacts the object? You can try {acContacts.label} or {acContacts.name} (or whatever attribute you wish to display).

Ok here's a bit more of my code
[Bindable]
private var acContacts:ArrayCollection;
private function retrieveData():void { //RETRIEVE DATA
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConn;
stmt.text = "SELECT * FROM tbl_person WHERE person_id=1";
stmt.execute();
var result:SQLResult = stmt.getResult();
acContacts = new ArrayCollection(result.data);
}
<mx:TextInput id="stagInput" text="{acContacts}" width="170" x="120" y="74"/>
The data comming from the query is information like first and last name, email, website .ect
I realize that my query currently has a hardcoded id but right now I'm just trying to get the users information displaying individual Textinputs - eg. one for first name one for last name .ect
Hope this explains my problem a bit better.
Thanks Again!

Here's what I was looking for
[Bindable]
private var acCon:ArrayCollection;
private function reData():void //RETRIEVE DATA
{
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConn;
stmt.text = "SELECT * FROM person";
stmt.execute();
var result:SQLResult = stmt.getResult();
acCon = new ArrayCollection(result.data);
}
<mx:Repeater id="repeater1" dataProvider="{acCon}">
<mx:Label id="Label1" text="{repeater1.currentItem.lastname}"/>

Related

Manipulating a database in C++

I apologize if has been asked, and answered somewhere else, but I have been searching like crazy and can't find what I'm looking for.
OleDbConnection^ conn = gcnew OleDbConnection ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Milestone3testdatabase.accdb; Persist Security Info=True");
OleDbCommand^ com = gcnew OleDbCommand();
com->Connection = conn;
com->CommandText = "SELECT *FROM tblcity;";
System::Data::DataSet^ ds = gcnew System::Data::DataSet();
OleDbDataAdapter^ adapt = gcnew OleDbDataAdapter();
adapt->SelectCommand = com;
adapt->Fill(ds,"why");
dataGridView1->DataSource = ds->Tables["why"];
I am trying to figure out how to actually use the data I obtain from the database. I was shown how to put it into a gridview, BUT I don't want a gridview. I want be able to take 1 cell of the table and display it as text.
How do I convert the table into usable data for a C++ forms application?
Either modify your SELECT so that it returns only a single value by using SqlCommand.ExecuteScalar Method or extract the value from your table with the DataTable.Select Method and DataTable.Rows Property
myDataTable->Rows[rowNumber][columnNumber]

MVVM database delete Method

I want to DELETE some items from my Model which I generated from the database like that:
db = new TestDBEntities();
foreach (var item in db.Farbe)
{
_model.Add(new Farbe { FarbauswahlNr = item.FarbauswahlNr, Kurztext = item.Kurztext, Ressource = item.Ressource,Vari1 = Convert.ToBoolean(item.Var1) ,Vari2 = item.Vari2 });
}
I'm showing this Model in a RadGridView and deleting by Selecting and Index per Rightcklick on the mouse like this:
public void ExecuteDelete(object obj)
{
farbliste.Model.Remove(SelectedIndex);
ListeAktualisieren();
}
Now the question is how do I Delete something from my Database because if I just Delete from my Model it wont work and that's also not what I want.
Btw some variable are named in German sorry...
you have to save your context. Your context in the first block of code is db.
So:
db = new TestDBEntities();
db.entity.Remove(db.entity.Find(SelectedIndex));
db.SaveChanges();
Entity is the name of your table/object from entity frramework. I would also suggest wraping this is a using block for the db

How can Add items to Binded Datasource Combo Box?

Hi I am new to C#. I have tried following way to add new item to my bound ComboBox but it won't give any result.
Is it possible to add new item to bound ComboBox (Here Problem is ID is Bigint data type but I want to add Select ID)?
If it is possible, please provide piece of code
try
{
objSqlExecute.OpenConnection();
string strQuery = objQueryManager.GetEmployeeRecords();
//Add Extra Items to combo Box
cmbEmployeeID.Items.Add("Select Id");
DataTable dtEmployee = objSqlExecute.GetRecordExecution(strQuery);
// DataRow dtNew = dtEmployee.NewRow();
// dtNew["ID"] = "Select ID";
// dtNew["FName"] = "";
//dtEmployee.Rows.InsertAt(dtNew, 0);
cmbEmployeeID.DataSource = dtEmployee;
cmbEmployeeID.DisplayMember = "ID";
cmbEmployeeID.ValueMember = "FName";
}
try
{
objSqlExecute.OpenConnection();
string strQuery = objQueryManager.GetEmployeeRecords();
//Add Extra Items to combo Box
DataTable dtEmployee = objSqlExecute.GetRecordExecution(strQuery);
cmbEmployeeID.DataSource = dtEmployee;
cmbEmployeeID.DisplayMember = "ID";
cmbEmployeeID.ValueMember = "FName";
cmbEmployeeID.Items.Insert(0, "None Selected");
}
Did you try your query to make sure it returns values? returning multiple records, single or none?
Do you want to add ONE new item at random intervals?
Or else do you have an option to INSERT all items at once?
Can you try adding toString() for converting BigInt?
Notes:
The arcticle here gives an insight to add a new item to a combobox using sql.
Looking at the questions you are posting, to see a sample of how to use ListItems in this scenario, you could refer to the web link.

How do I correctly use EF4 Navigation Properties?

I've created a database using the EF4 model-first approach. In my model, there's an N-to-M relationship between two entities:
I've filled my database with some dummy data, including 3 records of type Diagnosis and 3 records of type TreatmentSchema and associations between them. Here's the code snippet I used to do this:
using(var container = new SmartTherapyContainer()) {
var diagnosisA = new Diagnosis() { Id = Guid.NewGuid(), Name = "Diagnosis A" };
var diagnosisB = new Diagnosis() { Id = Guid.NewGuid(), Name = "Diagnosis B" };
var diagnosisC = new Diagnosis() { Id = Guid.NewGuid(), Name = "Diagnosis C" };
container.Diagnoses.AddObject(diagnosisA);
container.Diagnoses.AddObject(diagnosisB);
container.Diagnoses.AddObject(diagnosisC);
var schemaA = new TreatmentSchema() { Id = Guid.NewGuid(), Name = "Schema 1" };
var schemaB = new TreatmentSchema() { Id = Guid.NewGuid(), Name = "Schema 1" };
var schemaC = new TreatmentSchema() { Id = Guid.NewGuid(), Name = "Schema 1" };
container.Schemas.AddObject(diagnosisA);
container.Schemas.AddObject(diagnosisB);
container.Schemas.AddObject(diagnosisC);
diagnosisB.TreatmentSchemas.Add(schemaA);
diagnosisC.TreatmentSchemas.Add(schemaA);
diagnosisC.TreatmentSchemas.Add(schemaB);
diagnosisC.TreatmentSchemas.Add(schemaC);
container.SaveChanges();
}
I verified that the associations are indeed stored in the reference table created through EF4's mapping. However, when I retrieve a Diagnosis via the container.Diagnoses collection later, its .TreatmentSchemas collection is always empty.
I tried debugging into the EF4-generated code and all it does is lazily create said collection, but it doesn't fill it with the associated objects. Ayende's Entity Framework Profiler shows no queries being generated at all when the property is accessed, which leads me to believe that I'm doing something wrong here.
How can I get a list of the associated TreatmentSchemas?
Navigation properties are not loaded by default. You must use either eager loading or lazy loading but because you are using self tracking entities your choice is only eager loading because STEs don't support lazy loading. So if you want to get Diagonstic instance with all related TreatmentSchemas you must call:
var diagnosis = context.Diagnoses.Include("TreatmentSchemas").FirstOrDefault();

I can't get my SharePoint ListItem Fields

I want to show all fields of a certain ListItem. This includes LookUpFields and ChoiceFields. But I only seem to be able to show Textfields, like Title. How can I show all fields of my ListItem?
The problem is that I get an error when I try to show other fields of a listitem the way I got 'Title' to show, as if the strings I type in don't exist as fields in that listitem. But they do exist and are populated with values!
What is good way to show custom fields of a listitem without getting ObjectReference errors?
Also I get this error: The given key was not present in the dictionary.
private void foo()
{
using (ClientContext context = new ClientContext(ApplicationContext.Current.Url))
{
_list = context.Web.Lists.GetByTitle("MyList").Title);
_items = _list.GetItems(CamlQuery.CreateAllItemsQuery());
context.Load(_items);
context.ExecuteQueryAsync(
new ClientRequestSucceededEventHandler(OnListItemsRequestSucceeded),
new ClientRequestFailedEventHandler(OnListItemsRequestFailed));
}
}
private void OnListItemsRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{
// this is not called on the UI thread
Dispatcher.BeginInvoke(ShowListItemDetails);
}
public void ShowListItemDetails()
{
foreach (ListItem i in _items)
{
TextBox_Details.Text += i["Title"].ToString() + Environment.NewLine;
// Now the rest of the fields of this item.
}
}
Edit: What also is a big problem is I cant get the debugger working. This code is running as a Silverlight webpart on a local Sharepoint site. I attach the debugger to the iexplorer.exe but it won't break.
If I could get the debugger to work it would be a great help indeed.
you have tell the query what all fields you need to pull from lists
CamlQuery camlQuery = new CamlQuery();
camlQuery.ListItemCollectionPosition = itemPosition;
camlQuery.ViewXml =
#"<View>
<ViewFields>
<FieldRef Name='Title'/>
<FieldRef Name='Category'/>
<FieldRef Name='Estimate'/>
</ViewFields>
<RowLimit>10</RowLimit>
</View>";
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
for more details
http://msdn.microsoft.com/en-us/library/ee857094.aspx#SP2010ClientOM_Accessing_Large_Lists
To get item properties you will need to specify all the item properties you need in the second parameter of the ClientContext.Load method
e.g
string server = "http://localhost";
ClientContext context = new ClientContext(server);
Web web = context.Web;
var spList = web.Lists.GetByTitle("MyTitle");
CamlQuery query = new CamlQuery();
var items = spList.GetItems(query);
context.Load(items,
itema => itema.Include(
item => item,
item => item["ComplexProperty"]));
context.ExecuteQuery();`

Resources