9
Answers

General LINQ queries

TAN WhoAMI

TAN WhoAMI

11y
1.1k
1
say I have 2 columns, ColumnA and ColumnB from a table named TableAB,

with sets of data like this

ColumnA               ColumnB
======               ======
12345                   67890
54321                   67809
......                     ........
67890                   abcde
67809                   fghkm
.......                     .....

I would like to do a LINQ queries to give me results such that when the ColumnB values appear in ColumnA, then ColumnB gives the new values such that

Results
======
12345abcde
54321fghkm

Is this possible?

Appreciate if there is some code queries.

thanks.
Answers (9)
0
Amit Choudhary

Amit Choudhary

NA 27.7k 3m 14y
hi friend,

I have not concern the Comments. and you have to change the connection string i have used a demo connection string.

Here is your code for c#:

 SqlDataReader rdr1, rdr2;
              String localityid,villageid;
            try{
                SqlConnection cn=new SqlConnection(@"Data Source=.\SqlExpress;Initial Catalog=Demodb;Integrated Security=True;Pooling=False");
                SqlCommand cmd=new SqlCommand();
                string familyid=Request.QueryString["familyid"];
                cmd.CommandText="select * from HOUSEHOLDMEMBERS where FamilyId='"+familyid+"'";
                rdr1=cmd.ExecuteReader();
                 String tempMemberid="";
                 String tempNum="";
                while(rdr1.Read())
                {
                      tempMemberid=rdr1["MemberId"].ToString();
                }
                 int count1 = tempMemberid.Length;
                String memnum = tempMemberid.Substring(count1-2);
               
                int memno;
               if(int.TryParse(memnum,out memno))
                    memno++;
                String seqNo = memno.ToString();
                 if(memno < 10) {
                    tempMemberid = familyid + "0" + seqNo;
                }
                 else{
                    tempMemberid = familyid + seqNo;
                }


Please mark as answer if it helps