Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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
Updated 16-Nov-12 6:23am
v2
Comments
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...

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
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900