Showing posts with label datasource. Show all posts
Showing posts with label datasource. Show all posts

Tuesday, March 27, 2012

Binding WebService as Datasource

I've painstakingly managed to get a XmlDocument from a webservice and run this to retrieve data.

However, i cannot bind any of the returned elements to anything. Any help appreciated.


Are you using the XML data processing extension? What is the Query that you are using? More specifically, what is the Element Path for the query?

For more information, take a look at the following article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/RepServXMLDS.asp

Ian

Binding a DataSource Table column to a form object (RadioButtons)

Hi,

I have a little question. I have an application which interfaces with a SQL Express Database. On a form, I want to bind a control which is made of several Radio buttons to a table column which is in fact a varchar(1). This is the picture:

Table column: OptVisualRpt varchar(1)

Screen control: 2 radio buttons

rb_VisRPTbImp_O for "yes"

rb_VisRPTbImp_N for "no"

I'm really scratching my head as how I can bind a single table column to my radio buttons controls. I think that I just can't this way but rather have to use an intermediate variable or control.

Solution 1?

I thought of using a local variable that I would set to "y" or "n" following "CheckedChanged" events fired from radio buttons but I don't know how to bind this variable to my table column.

Solution 2?

I thought of placing a hidden text control into my form, which one would be binded to my table column, that I would also set to "y" or "n" following "CheckedChanged" events fired from radio buttons.

Any of these solutions which would be feasible or any more neat way to do it?

Many thanks in advance,

Stphane

Hi again,

Finally sounds that last night I could solve my problem by myself. Let me explain.

1- I first got rid of the "Binding source". I removed following lines:

=> private: System::Windows::Forms::BindingSource ^ InfoBaseBindingSource;

=> this->InfoBaseBindingSource = (gcnew System::Windows::Forms::BindingSource(this->components));

=> (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->InfoBaseBindingSource))->BeginInit();

=> //
// InfoBaseBindingSource
//

this->InfoBaseBindingSource->DataMember = L"InfoBase";
this->InfoBaseBindingSource->DataSource = this->Test_ADODataSet;

=> (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->InfoBaseBindingSource))->EndInit();

2- At the same time, for every field control that were fed by it, I removed from code the following line (here is an example):

this->ID_Compagnie->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->InfoBaseBindingSource, L"Identification", true)));

3- I then changed the Form1_Load routine for the following:

this->InfoBaseTableAdapter->Fill(this->Test_ADODataSet->InfoBase);

DataTable ^ Dt_Infobase = this->Test_ADODataSet->Tables["InfoBase"];
if(Dt_Infobase != nullptr)
{
array<DataRow^> ^ Rw_InfoBase = Dt_Infobase->Select();
if(Rw_InfoBase->Length != 0)
{
this->ID_Compagnie->Text = Rw_InfoBase[0]["Identification"]->ToString();
this->Adr_Compagnie->Text = Rw_InfoBase[0]["Adresse"]->ToString();
...

==> Example of loading a masked text box

// Affichage et rectification du format du Code Postal/ZipCode

if(String::Compare(this->Pays_Compagnie->Text,"Canada") == 0)
{
this->CPZip_Compagnie->Mask = ">L0>L 0>L0";
this->Pnl_VSZCode->Hide();
}
else
{
this->Pnl_VSZCode->Show();
if(this->CPZip_Compagnie->Text->Length > 5)
{
this->VScrl_ZCode->Value = 1;
this->CPZip_Compagnie->Mask = "99999";
}
else
{
this->VScrl_ZCode->Value = 0;
this->CPZip_Compagnie->Mask = "99999-9999";
}
}

this->CPZip_Compagnie->Text = Rw_InfoBase[0]["CodePostal_Zip"]->ToString();

...

==> Example of "loading" info vs a set of radio buttons

String ^ Logo_ModeAff = Rw_InfoBase[0]["LogoRpt_ModeAff"]->ToString();
if(Logo_ModeAff == "C")
{
this->rb_ModeAffLCoord->Checked = true;
this->rb_ModeAffLOnly->Checked = false;
}
else
{
this->rb_ModeAffLCoord->Checked = false;
this->rb_ModeAffLOnly->Checked = true;
}
}

4- I then changed the B_Accept_Click routine for the following:

I removed following sentences:

this->InfoBaseBindingSource->EndEdit();
this->InfoBaseTableAdapter->Update(this->Test_ADODataSet->InfoBase);
this->Test_ADODataSet->AcceptChanges();

And replaced them with following:

DataTable ^ Dt_Infobase = this->Test_ADODataSet->Tables["InfoBase"];
if(Dt_Infobase != nullptr)
{
array<DataRow^> ^ Rw_InfoBase = Dt_Infobase->Select();
if(Rw_InfoBase->Length == 0)
{
DataRow ^ NRw_InfoBase = Dt_Infobase->NewRow();

NRw_InfoBase["Identification"] = this->ID_Compagnie->Text;
...
==> Example of a "saving" info vs a set of radio buttons

if(this->rb_ModeAffLCoord->Checked == true)
NRw_InfoBase["LogoRpt_ModeAff"] = "C";
else
NRw_InfoBase["LogoRpt_ModeAff"] = "L";
...

Dt_Infobase->Rows->Add(NRw_InfoBase);
}
else
{
Rw_InfoBase[0]["Identification"] = this->ID_Compagnie->Text;
...
==> Example of a "replacing" info vs a set of radio buttons

if(this->rb_ModeAffLCoord->Checked == true)
Rw_InfoBase[0]["LogoRpt_ModeAff"] = "C";
else
Rw_InfoBase[0]["LogoRpt_ModeAff"] = "L";
...
}

this->InfoBaseTableAdapter->Update(this->Test_ADODataSet);
this->Test_ADODataSet->AcceptChanges();
}

5- I finally changed the B_Cancel_Click routine for the following:

I removed following sentences:

this->InfoBaseBindingSource->EndEdit();

This code is maybe not the best way to do it. If someone has any more proper way to do it, I would certainly appreciate to learn. My conclusion is that doing this binding process manually gives better results than relying on a BindingSource object.

Stphane

Sunday, March 25, 2012

Bind DataSource at runtime and Adding fields [A little help please]

hi,

I am using Crystal Reports 8.5 and Visual Biasic 6.0, the technique that I
was using was I connect the database using the ODBC to the crytal reports and design my report by draging the fields to the reports.

In my new assignment I have to bind a ADODB recordset to the report at
run time.

I got 2 Problems.

01. How can I bind a ADODB recordset to the report at run time
02. After binding the recordset how can I add the fileds to the report
content area

A small help on this please.

Thank you.Dim conn As ADODB.Connection 'CONNECTION TO BROKER QUERIES
Dim rs As ADODB.Recordset 'HOLDS ALL DATA RETURNED FROM QUERY
Dim crystal As CRAXDRT.Application 'LOADS REPORT FROM FILE
Dim Report As CRAXDRT.Report 'HOLDS REPORT

Set conn = New ADODB.Connection
conn.Open "Provider=MSDAORA.1;User ID=scott;Data Source=qb;Persist Security Info=False", "sebsv4", "sebsv4pwd" 'THESE OPTION VALUES ARE BEST FOR VB

Set rs = New ADODB.Recordset
rs.Open q, conn, adOpenStatic, adLockReadOnly

Set crystal = New CRAXDRT.Application 'MANAGES REPORTS

Set Report = crystal.OpenReport(App.Path & "\report1.rpt") 'OPEN OUR REPORT

Report.DiscardSavedData 'CLEARS REPORT SO WE WORK FROM RECORDSET
Report.Database.SetDataSource rs 'LINK REPORT TO RECORDSET

CRViewer1.ReportSource = Report 'LINK VIEWER TO REPORT
CRViewer1.ViewReport 'SHOW REPORT|||thanks for the quick reply sraheem

another small problem,

if I am using the report designer in VB like that, when I have draged a field name in to the report
it shows the field name as

field:<TableName>.<ColumnName>

now If I am doing the data binding at run time how can I add the recordset columns in to the report, since there is no data property on report fileds

Thanx.|||just capture report sections like below and add fields...

Dim crxdetail As CRAXDDRT.Section 'Section Decleration
Dim crxPageHeader As CRAXDDRT.Section 'Section Decleration
Dim crxPageFooter As CRAXDDRT.Section 'Section Decleration

Set crxdetail = Report.Sections.Item("D") 'Detail Section
Set crxPageHeader = Report.Sections.Item("PH") 'Detail Section
Set crxPageFooter = Report.Sections.Item("PF") 'Detail Section

crxdetail.AddFieldObject "{e." & rs(i).Name & "}", 1000, 0

where e is the report command object name or table name in your case.