Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
SqlCommand SqlComm = new SqlCommand();
SqlComm.Connection = conn;
SqlComm.CommandType = CommandType.Text;
SqlComm.CommandText = "select jobcard_creation.jobcard_no,jobcard_creation.vehicle_no,jobcard_creation.vehicle_model,jobcard_creation.date, jobcard_staff.staff_name, "
     + "  jobcard_creation.delivery_date,jobcard_creation.total_days,vehicle_type.vehicle_name,Job_type.jobtype_name from jobcard_creation "
    + " left outer join vehicle_type on jobcard_creation.department_id=vehicle_type.vehicle_id   left outer join Job_type on job_type.jobtype_id=jobcard_creation.job_type  "
    + " left join jobcard_staff on jobcard_staff.jobcard_id=jobcard_creation.jobcard_id  where "
    + " jobcard_creation.jobcard_id='" + txtJobCardId.Text + "' and jobcard_creation.type='N' and jobcard_staff.type='N' ";  

SqlCommand sqlcom1 = new SqlCommand();
sqlcom1.Connection = conn;
sqlcom1.CommandType = CommandType.Text;
sqlcom1.CommandText="select describtion from jobcard_work_description where jobcard_id='" + txtJobCardId.Text + "' ";
// Create instance of Northwind DataSetXSD
Posted
Updated 20-May-15 1:35am
v2
Comments
Richard Deeming 20-May-15 7:52am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

You just need to join on the jobcard_work_descriptiontable and include describtion in your select clause (although I suspect it should be description) E.g.
SQL
select JC.jobcard_no,JC.vehicle_no,JC.vehicle_model,JC.[date], JS.staff_name,
        JC.delivery_date,JC.total_days,VT.vehicle_name,JT.jobtype_name,
        JWD.describtion
from jobcard_creation JC
left outer join vehicle_type VT on JC.department_id=vt.vehicle_id
left outer join Job_type JT on JT.jobtype_id=JC.job_type
left join jobcard_staff JS on JS.jobcard_id=JC.jobcard_id
left join jobcard_work_description JWD on JC.jobcard_id=JWD.jobcard_id
where JC.jobcard_id=@cardid and JC.[type]='N' and JS.type='N'


Couple of things to note:
- I've surrounded column names that are reserved words with square brackets e.g. [type] and [date]
- I've used table aliases to make the select clause a bit more readable e.g. JC, JT, VT etc.
- Take note of the comment from Richard Deeming - NEVER use string concatenation to build a SQL query. See @cardid in my query above
 
Share this answer
 
Comments
sekar305 20-May-15 8:10am    
jobcard_work_description table fetch many values from table, and view it separately,so i write separate query for jobcard_work_description,,,


so i want to merge two tables in dataset...
CHill60 20-May-15 8:12am    
You can't merge two tables that are completely different shapes - you can have more than one table in a dataset however. What are you actually trying to achieve?
sekar305 20-May-15 8:22am    
ok i have null value in some field (jobcard_work_description) table,so i have not to display null values in dataset
CHill60 20-May-15 8:27am    
Do you mean don't display description if it is null, or don't display anything if description is null?
You're not being very clear
sekar305 20-May-15 8:22am    
Staff Name

selvam-GI00099-SD00000040

Govindraj-025-SD00000041





Describtion



order of painting and thinkiring

front rear mirror need
Another approach could be like. Check this[^] for Reference!

C#
public DataSet SelectOne(int id)
{
    DataSet result = new DataSet();
    using (DbCommand command = Connection.CreateCommand())
    {
        command.CommandText = @"
select * from table1
select * from table2
        ";

        var param = ParametersBuilder.CreateByKey(command, "ID", id, null);
        command.Parameters.Add(param);

        Connection.Open();
        using (DbDataReader reader = command.ExecuteReader())
        {
            result.MainTable.Load(reader);
            reader.NextResult();
            result.SecondTable.Load(reader);
            // ...
        }
        Connection.Close();
    }
    return result;
}
 
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