loveuajay
asked on
sql to linq in c# code
cn.Open();
SqlCommand cmsql;
SqlDataReader drsql;
string sql = "select max(patientid)as patientid from patient";
cmsql = new SqlCommand(sql, cn);
drsql = cmsql.ExecuteReader();
if (drsql.Read())
{
int pid = Convert.ToInt16(drsql["patientid"].ToString()) + 1;
txtpatientid.Text = pid.ToString();
}
else
{
txtpatientid.Text = "1";
}
cn.Close();
cmsql.Dispose();
drsql.Close();
this is my sql code how i make it in linq
my table name is== patient
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i get this error
Error 1 The type or namespace name 'DataContextType' could not be found (are you missing a using directive or an assembly reference?) D:\ajay\jolly tech project\jollytech p1\jollytech p1\patient.cs 79 26 jollytech p1
Error 1 The type or namespace name 'DataContextType' could not be found (are you missing a using directive or an assembly reference?) D:\ajay\jolly tech project\jollytech p1\jollytech p1\patient.cs 79 26 jollytech p1
Hi loveuajay;
When working with Linq to SQL the first thing you need to do is create your data context and in Linq to SQL it is creating a EDMX which is Object Relational/Model, This model defines the tables in the database and the relationships between them. I would suggest reading the following web link which describe what LinQ to SQL is and how to create the OR/M, EDMX file and querying the database.
Using Linq to SQL Part 1
Once you have created the EDMX file which maps the database to the classes in your code that is what you will use for the variable DataContextType in the code snippet I posted.
When working with Linq to SQL the first thing you need to do is create your data context and in Linq to SQL it is creating a EDMX which is Object Relational/Model, This model defines the tables in the database and the relationships between them. I would suggest reading the following web link which describe what LinQ to SQL is and how to create the OR/M, EDMX file and querying the database.
Using Linq to SQL Part 1
Once you have created the EDMX file which maps the database to the classes in your code that is what you will use for the variable DataContextType in the code snippet I posted.
ASKER
thanks i get it
Not a problem, glad to help.
Open in new window