first of all there is a searchbox form and a view form. after passing the value of the id in the searchbox, it should return all the values that matches with the id of that person after the textchange method occured. but it doesn't display a single value on the textboxes. here is my code
public void first_tab_search(string key)
{
key = txtSearch.Text;
var first = from a in dbcon.personal_informations where a.last_name == key select a;
foreach (var setThem in first)
{
txtsurname.Text = setThem.last_name;
txtfirstname.Text = setThem.first_name;
txtmiddlename.Text = setThem.middle_name;
txtID.Text = setThem.userid;
txtweight.Text = setThem.weight;
txttin.Text = setThem.tin;
txtsss.Text = setThem.sss;
txtaeno.Text = setThem.agency_employee_no;
txtbloodtype.Text = setThem.blood_type;
txtcitizenship.Text = setThem.citizenship;
txtcivilstatus.Text = setThem.civil_status;
txtcpno.Text = setThem.cell_no;
txtdob.Text = setThem.datetime_of_birth.ToString();
txtemail.Text = setThem.email_address;
txtgender.Text = setThem.sex;
txtgsis.Text = setThem.gsis_id;
txtheight.Text = setThem.height;
txtnameext.Text = setThem.name_ext;
txtpagibig.Text = setThem.pagibig_id;
txtpermaaddr.Text = setThem.permanent_address;
txtpermatelno.Text = setThem.permanent_telno;
txtpermazip.Text = setThem.permanent_zipcode;
txtphilhealth.Text = setThem.philhealth;
txtpob.Text = setThem.place_of_birth;
txtresidentialaddr.Text = setThem.residential_address;
txtresitelno.Text = setThem.residential_telno;
txtresizip.Text = setThem.residential_zipcode;
txtweight.Text = setThem.weight;
}
}
You have a whole host of problems going on here.
You pass a key into the method, and then immediately overwrite it with the contents of your search box.
Your search could return more than one result, and therefore your code is looping through each result and overwriting the output values with the last returned row. Use += rather than + in your loop, i.e.
txtsurname.Text += setThem.last_name;
Your code is currently case sensitive, this may be the desired approach but might not be.
Related
I have a checkedListBox on a winform.
I fill the check box with some code see below.
All works well.
Now I need to get the value of the checked items. I am having some issues.
When I do the foreach(var item in clbtest.CheckedItems)
I get this when doing a Immediate window... ? item
{ Text = "Depos", Value = "Q:\\Scanning Department\\_DT SEARCH INDEXES\\Depos" }
Text: "Depos"
Value: "Q:\\Scanning Department\\_DT SEARCH INDEXES\\Depos"
I don't know how to get at the Value field. I have tried several ways but nothing seems to work.
private void FillIndexes()
{
string stext = cblIndexToSearch.Text;
cblIndexToSearch.Items.Clear();
cblIndexToSearch.Text = "";
cblIndexToSearch.DisplayMember = "Text";
cblIndexToSearch.ValueMember = "Value";
foreach (var item in indexlist)
{
cblIndexToSearch.Items.Insert(0,
new { Text = item.indexName, Value = #item.indexPath });
}
}
Hope this helps. Just create a checklistbox named "checkedListBox1" and the code should work. I detailed a little on what it does.
checkedListBox1.Items.Clear();
checkedListBox1.Text = "";
checkedListBox1.DisplayMember = "Text";
checkedListBox1.ValueMember = "Value";
checkedListBox1.Items.Insert(0,
new { Text = "Rawr", Value = "Whatever 2011"});
string temp = checkedListBox1.Items[0].ToString(); //gets the string of the item. (switch 0 to the index you want)
string string_Value = temp.Split(new string[] { "Value = " }, StringSplitOptions.None)[1]; //splits the string by the value part and returns the string value.
string_Value = string_Value.Substring(0, string_Value.Length - 2); ; //removes the last 2 characters since they are not part of the value.
//you now have the value in string form.
I have the following function which works fine and produces the results when their is one table selected. But when there is two tables being selected my _newList function is just replacing the fields in the array I will show you in graphical form best i can.
private void genXmlSchema_Click(object sender, EventArgs e)
{
List<TableDefnition> _newList = new List<TableDefnition>();
PersistentObject _testObjects = new PersistentObject();
List<GridViewRowInfo> _checkRows = GetCheckedRows(rgTableNames);
List<PersistentObject> _testObjectsList = new List<PersistentObject>();
foreach (GridViewRowInfo row in _checkRows)
{
var currentRow = (TableNames)row.DataBoundItem;
_newList = db.GetALLTableDeiniations(currentRow.TABLE_NAME);
rgFieldsOfTable.DataSource = db.GetALLTableDeiniations(currentRow.TABLE_NAME);
_testObjectsList.Add( BuildSchema(_newList, currentRow.TABLE_NAME));
}
_newPObject.PersistentObjects.AddRange(_testObjectsList);
_newPObject.ClassPrefix = "Persistent";
_newPObject.ClassSuffix = "";
_newPObject.Language = "VB";
_newPObject.Path = #"C:\Sage200SchemaExtensions";
_newPObject.GenerateSeparateFiles = "false";
_newPObject.GenerateBusinessObjects = "false";
_newPObject.BaselineSchema = #"C:\Program Files (x86)\Sage 200 SDK\SageObjectStore.xml";
_newPObject.DataTypes = "";
_newPObject.Enumerations = "";
_newPObject.MemberVariablePrefix = "_";
_newPObject.ApplicationNamespace = "BusinessObjects";
schemeContent.Text = HelperXml.ToXML(_newPObject);
}
On the second pass you will that it has duplicated the second table in both of the lists.
First Array Number after second pass
Second Array Number after second pass
As you can clearly see its lost the reference to the first table with 4 columns completely I no its something simple to do with my list creation and destruction but cant figure it out
When i run my application i get an error that not all the fields of the table tblContact are filled. How do i edit in my code that if a record is null I show in my application null.
Here is my code:
public void SelID(int Zoek)
{
string SQL = "select * from tblContact";
SQL += " where cNr=" + Zoek.ToString();
DataTable DT = Database.ExecSelect(SQL);
if (DT.Rows.Count == 0)
{
pr_cNr = -1;
}
else
{
pr_cNr = (int)(DT.Rows[0]["cNr"]);
pr_cVNaam = (string)(DT.Rows[0]["cVnaam"]);
pr_cTNaam = (string)(DT.Rows[0]["cTNaam"]);
pr_cANaam = (string)(DT.Rows[0]["cAnaam"]);
pr_cAdres = (string)(DT.Rows[0]["cAdres"]);
pr_cPost = (string)(DT.Rows[0]["cPost"]);
pr_cPlaats = (string)(DT.Rows[0]["cPlaats"]);
}
}
try this way:
object val = row["ColumnName"];
if (val == DBNull.Value)
// your code
else
//your code
using inline checking for all columns makes your code messy and error-prone.
It seems, you have to check for null:
...
else
{
// In case of integer we have to specify how null should be treated:
pr_cNr = DT.Rows[0].IsNUll("cNr")
? -1 // or whatever default value
: Convert.ToInt32(DT.Rows[0]["cNr"]);
// In case of string Convert.ToString(DBNull.Value) returns empty string ""
// Please, notice that original (string) (DBNull.Value) throws exception
pr_cVNaam = Convert.ToString(DT.Rows[0]["cVnaam"]);
pr_cTNaam = Convert.ToString(DT.Rows[0]["cTNaam"]);
pr_cANaam = Convert.ToString(DT.Rows[0]["cAnaam"]);
pr_cAdres = Convert.ToString(DT.Rows[0]["cAdres"]);
pr_cPost = Convert.ToString(DT.Rows[0]["cPost"]);
pr_cPlaats = Convert.ToString(DT.Rows[0]["cPlaats"]);
}
In my application I would like add Brand and MPN to existing eBay item via API on C#, so, I run code:
string eCommerceID = (dr["eCommerceID"] ?? "").ToString().Trim();
string upc = (dr["UPC"] ?? "").ToString().Trim();
string manufacturerName = (dr["ManufacturerName"] ?? "").ToString().Trim();
string brandMPN = (dr["BrandMPN"] ?? "").ToString().Trim();
ReviseItemRequestType reviseItemRequestType = new ReviseItemRequestType();
reviseItemRequestType.Version = version;
reviseItemRequestType.Item = new ItemType();
reviseItemRequestType.Item.ItemID = eCommerceID;
reviseItemRequestType.Item.ProductListingDetails = new ProductListingDetailsType();
reviseItemRequestType.Item.ProductListingDetails.UPC = upc;
reviseItemRequestType.Item.ProductListingDetails.BrandMPN = new BrandMPNType();
reviseItemRequestType.Item.ProductListingDetails.BrandMPN.Brand = manufacturerName;
reviseItemRequestType.Item.ProductListingDetails.BrandMPN.MPN = brandMPN;
ReviseItemResponseType reviseItemResponseType = ebayService.ReviseItem(reviseItemRequestType);
but when I execute this code, eBay returns error:
"The item specific Brand is missing. Add Brand to this listing, enter a valid value, and then try again."
What I'm doing wrong?
Appreciate any help. Thanks.
Error:
As the error messages says:
The item specific Brand is missing
Don't use the Item.ProductListingDetails.BrandMPN in your request. Instead you will need to create two Item Specifics called Band and MPN.
<ItemSpecifics>
<NameValueList>
<Name>Brand</Name>
<Value>[BRAND VALUE]</Value>
</NameValueList>
<NameValueList>
<Name>MPN</Name>
<Value>[MPN VALUE]</Value>
</NameValueList>
</ItemSpecifics>
Here is copy paste code snippet of the C# solution.
ItemType itemType = new ItemType(); // = class eBay.Service.Core.Soap.ItemType
Int32 condCodeAsInt = 1000; // upto you to derrive this from your use case.
String myBrandValue = "Some BRAND";
String myMpnValue = "some MPN";
String myUpcValue = "Does not apply";
....
//if condition is "New" or "New with Details" then we need to set extra REQUIRED fields
if (condCodeAsInt == 1000 || condCodeAsInt == 1500)
{
//if it is "new" then remove inputted desc text completely REQUIRED
if (condCodeAsInt == 1000)
{
itemType.ConditionDescription = "";
}
// set UPC value HERE, not in ItemSpecifics.
ProductListingDetailsType pldt = new ProductListingDetailsType();
pldt.UPC = myUpcValue;
itemType.ProductListingDetails = pldt;
//init Item specifics ( and set BRAND and MPN )
itemType.ItemSpecifics = new NameValueListTypeCollection();
//brand
NameValueListType nvBrand = new NameValueListType();
nvBrand.Name = "Brand";
StringCollection brandStringCol = new StringCollection();
brandStringCol.Add(myBrandValue);
nvBrand.Value = brandStringCol;
itemType.ItemSpecifics.Add(nvBrand);
//MPN
NameValueListType nvMpn = new NameValueListType();
nvMpn.Name = "MPN";
StringCollection mpnStringCol = new StringCollection();
mpnStringCol.Add(myMpnValue);
nvMpn.Value = mpnStringCol;
itemType.ItemSpecifics.Add(nvMpn);
}
I'm trying to get back 2 unique images form an array. Right now I'm refreshing the page until I get 2 unique images. This is not ideal. How can I modify this code to back 2 unique images with out refreshing the page till it hapens.
Can I do it in this layer or do I need to check for unique numbers in the data layer?
Picture dlPicture = new Picture();
DataTable DTPictures = dlPicture.GetRandomPicture();
Picture dlPicture2 = new Picture();
DataTable DTPictures2 = dlPicture2.GetRandomPicture();
// the variables to hold the yes and no Id's for each set
string firstNoPicId = "";
string firstYesPicId = "";
string secondNoPicId = "";
string secondYesPicId = "";
foreach (DataRow row in DTPictures.Rows)
{
firstYesPicId = row["PicID"].ToString();
secondNoPicId = firstYesPicId;
FirstPicMemberNameLabel.Text = row["MemberName"].ToString();
FirstPicLink.ImageUrl = "Pictures/" + row["PicLoc"];
}
foreach (DataRow row in DTPictures2.Rows)
{
secondYesPicId = row["PicID"].ToString();
firstNoPicId = secondYesPicId;
SecondPicMemberNameLabel.Text = row["MemberName"].ToString();
SecondPicLink.ImageUrl = "Pictures/" + row["PicLoc"];
}
if (firstYesPicId != secondYesPicId)
{
FirstPicLink.PostBackUrl = "default.aspx?yesId=" + firstYesPicId + "&noId=" + firstNoPicId;
SecondPicLink.PostBackUrl = "default.aspx?yesId=" + secondYesPicId + "&noId=" + secondNoPicId;
}
else
{
Response.Redirect("Default.aspx");
}
There two pretty obvious ways to deal with this
Add an overload dlPicture.GetRandomPicture(int picID) This will accept an ID so that it won't return an already used picID
restructure your code so that it loops until the secondYesPicId != firstYesPicId
Something like
secondYesPicId = firstYesPicId;
while (firstYesPicId == secondYesPicId)
{ DataTable DTPictures2 = dlPicture2.GetRandomPicture();
foreach (DataRow row in DTPictures2.Rows)
{
secondYesPicId = row["PicID"].ToString();
SecondPicMemberNameLabel.Text = row["MemberName"].ToString();
SecondPicLink.ImageUrl = "Pictures/" + row["PicLoc"];
}
}
Perhaps a better solution would be adding code to your datalayer.GetRandomPicture to make sure it can't return the same picture twice in a row?
in this Picture class add a LastRandomPictureID variable and do a 'WHERE NOT ID = LastRandomPictureID' on your query (you might want to make it a bit more robust to handle the case where only 1 picture exists).
var rnd = new Random();
int randomPicIndex1 = rnd.Next(numOfPictures);
int randomPicIndex2;
do {
randomPicIndex2 = rnd.Next(numOfPictures);
} while (randomPicIndex1 == randomPicIndex2);
Then use these indexes in order to get random rows from your table.
DataRow row1 = DTPictures.Rows[randomPicIndex1];
DataRow row2 = DTPictures.Rows[randomPicIndex2];