Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
string querycheck = "SELECT sponcorid FROM Registration_Master WHERE regCode='" + temp + "'";
                         //string parent = (string)com.ExecuteScalar();
                         com = new SqlCommand(querycheck, con);
                         com.CommandType = CommandType.Text;
                         da = new SqlDataAdapter(com);
                         DataTable dtcheck = new DataTable();
                         da.Fill(dtcheck);
                         string parent = dtcheck.Rows[0]["sponcorid"].ToString();
I want this sponcorid database value should be put in this parent variable how can do this it gives me blank value when i use this logic, please help me
 
[Edit]Code block added[/Edit]
Posted 16-Nov-12 7:22am
Edited 16-Nov-12 7:23am
ProgramFOX132.5K
v2
Comments
csharpbd at 16-Nov-12 15:05pm
   
When you run your code please see you have any data in your "dtcheck" DataTable? If no data check your parameter value comparing with database table value there are any row who have same value...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First, check your temp varaible - make sure the content is what you are expecting.
Then, check your database and make sure that at least one row has a matching regCode value - exactly matching, including any spaces.
Finally, check that the matching rows have a value in the sponcorid column.
 
Chances are it's a data problem of some sort - and one of the above will catch it.
 
BTW: I don't know where you get your temp value from, but be careful - concatenating strings is a dangerous way to build an SQL command. It leaves you wide open to an SQL Injection attack which can accidentally or deliberately damage or destroy your database. It is a good idea to use parametrized queries at all times instead.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi
 
Hi
Are you sure, if you execute this query [with value in temp] in database directly, you will get the result? Because i guess, it might be the issue with your query/data . Can you execute the query with data in 'temp' and check the result. If you get the result , then you use the same query in your code. This is for just to confirm whether there is any issue with data.
I.E . For Ex:
string querycheck = "SELECT sponcorid FROM Registration_Master WHERE regCode = '001'
 
And instead of using DataTable, can you check by using DataSet.
 
Regards
Dominic
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 495
1 Maciej Los 258
2 OriginalGriff 229
3 BillWoodruff 170
4 Zoltán Zörgő 165
0 OriginalGriff 7,934
1 DamithSL 6,084
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,174
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100