Filling BO


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Ian,

I am not a C# developer but there are a lot places in the web which will help you converting from one language to the other.



Here my previous VB code converted to C# from http://www.developerfusion.com/tools/convert/vb-to-csharp/



public void FindDuplicateTransactionItem(int pFK_Items, string pCardLotNo, int pSerialNumber_Start, int pCardQty)

{

//-- Establish Locals

using (SqlCommand cmd = new SqlCommand()) {

//-- Build the command

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "dbo.spFindDuplicateCardItem";



//-- Create and set the parameters

cmd.Parameters.AddWithValue("@pFK_Items", pFK_Items).SqlDbType = SqlDbType.Int;

cmd.Parameters.AddWithValue("@pCardLotNo", pCardLotNo).SqlDbType = SqlDbType.VarChar;

cmd.Parameters.AddWithValue("@pStartSerialNumber", pSerialNumber_Start).SqlDbType = SqlDbType.Int;

cmd.Parameters.AddWithValue("@pCardQuantity", pCardQty).SqlDbType = SqlDbType.Int;

this.FillDataTable(cmd);

}

}





Now back to your problem, I believe what you want is just get the this.trkpdt.Text value based on the Trk_lic.Text value, if so, take a look in the help file on how to create an Scalar method in your BO that will return that trkpdt value.



What you are doing now is not going to work because you are clearing the PrimaryBusinessObject of the form which I assume is this.truckBO1 and then filling it with the data to get the Trk_lic.Text value. Spend some time with the SF help file which have pretty good examples of Scalar methods or search in the forums for more real examples. These are functionality that mostly every application will use and if you learn it well, then you can re-use whenever you need it.

Edhy Rijo

Ian Johnston
Ian Johnston
StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)
Group: StrataFrame Users
Posts: 77, Visits: 470
So can you show me how to add one parameter in C#. I get as far as SqlDbType and it is not offering int or Varchar as an option. Also I see the

Also I don't know if the way I set it up is the problem but I have the followoing code in the leave event of a textbox:

private void Trk_lic_Leave(object sender, EventArgs e)

{

this.truckBO1.Clear();

this.truckBO1.pdt_data(Trk_lic.Text);

if (this.truckBO1.Count > 0)

{

this.trkpdt.Text = this.truckBO1.truck_pdt.ToString();

}

}

This runs the query on the BO and returns a value which is agssigned to the text value of a label if one is found. the problem I am having is that after this the CertFrm_FormEditingStateChanged event is triggered and the form starts back at tab order 0 and the only wayto get to the next textbox after this is to click into it, if you tab through the form you go back to zeo when tabbing out of this textbox.


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Ian,



Edhy's right on the money that you always want to use parametrized queries, instead building them by directly placing anything that is changeable directly into the string. Two reasons: to prevent SQL injection and to allow SQL server to cache the request, so it doesn't need to be compiled every time. It also means that you don't have to worry about how to get the data from a .net type into the correct form for the SQL statement.



Ian Johnston
Ian Johnston
StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)
Group: StrataFrame Users
Posts: 77, Visits: 470
Thanks. Got it working once I got close enough to the screen to se the ' & " !
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Ian,

I believe the problem is that the truck_license field type is varchar and if so you need to wrap the value of lic with quotations, something like this:

"select * from truck where truck_license = '"+ lic + "'";




Also much safer way to create your SQL statements is like this (VB):



Public Sub FindDuplicateTransactionItem(ByVal pFK_Items As Integer, ByVal pCardLotNo As String, ByVal pSerialNumber_Start As Integer, ByVal pCardQty As Integer)

'-- Establish Locals

Using cmd As New SqlCommand()

'-- Build the command

cmd.CommandType = CommandType.StoredProcedure

cmd.CommandText = "dbo.spFindDuplicateCardItem"



'-- Create and set the parameters

cmd.Parameters.AddWithValue("@pFK_Items", pFK_Items).SqlDbType = SqlDbType.Int

cmd.Parameters.AddWithValue("@pCardLotNo", pCardLotNo).SqlDbType = SqlDbType.VarChar

cmd.Parameters.AddWithValue("@pStartSerialNumber", pSerialNumber_Start).SqlDbType = SqlDbType.Int

cmd.Parameters.AddWithValue("@pCardQuantity", pCardQty).SqlDbType = SqlDbType.Int



Me.FillDataTable(cmd)

End Using



End Sub





Take a look at the help file for more samples.

Edhy Rijo

Ian Johnston
Ian Johnston
StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)StrataFrame User (219 reputation)
Group: StrataFrame Users
Posts: 77, Visits: 470
I am trying to fill a BO with filtered data , can anyone tell me what I need to change ?

public void pdt_data(string lic)

{

string s = "select * from truck where truck_license = "+lic;

FillDataTable(s);

}


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search