Click here to Skip to main content
13,085,613 members (90,805 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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();
                         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 6:22am
Updated 16-Nov-12 6:23am
csharpbd 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
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2017
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