TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
189
25k
how to retrieved data from given id and without using EF?
May 9 2018 2:57 AM
public List<ClientProduct> GetProducts(string id)
{
//
List<ClientProduct> clproduct = new List<ClientProduct>();
using (MySqlConnection con = new MySqlConnection())
{
con.ConnectionString = constr;
using (MySqlCommand cmd = new MySqlCommand())
{
//ClientProduct p = new ClientProduct();
cmd.Connection = con;
cmd.CommandText = "SELECT cm.ClientId,cm.ClientName, pa.ProductName,cp.ClProductId,cp.ProductId,cp.ParentProductId,cp.Act_Date,cp.Exp_Date,cp.ClientProductDetail "
+ "FROM ClientMaster cm inner join ClientProduct cp on cm.ClientId = cp.ClientID "
+ "inner join ProductMaster pa ON pa.ProductId = cp.ProductId where cm.ClientId=@ClientId";
cmd.Parameters.AddWithValue("@ClientId", id);
//cmd.Parameters.AddWithValue("@ClientId",id);
//where cm.ClientId='" + cp.ClientID + "'
con.Open();
using (MySqlDataReader sdr = cmd.ExecuteReader())
{
if (sdr.HasRows)
{
while (sdr.Read())
{
ClientProduct cp = new ClientProduct();
cp.ClientID = sdr["ClientId"].ToString();
cp.ClientName = sdr["ClientName"].ToString();
cp.CLProductId = sdr["CLProductId"].ToString();
cp.ProductId = sdr["ProductId"].ToString();
cp.ProductName = sdr["ProductName"].ToString();
cp.ClientProductDetail = sdr["ClientProductDetail"].ToString();
cp.ParentProductId = sdr["ParentProductId"].ToString();
if (DBNull.Value != sdr["Act_Date"])
{
cp.Act_Date = sdr["Act_Date"].ToString();
}
else
{
cp.Act_Date = null;
}
if (DBNull.Value != sdr["Exp_Date"])
{
cp.Exp_Date = sdr["Exp_Date"].ToString();
}
else
{
cp.Exp_Date = null;
}
clproduct.Add(cp);
}
}
}
con.Close();
}
}
return clproduct;
}
//Controller
public ActionResult ClientProductList(string id)
{
return View(GetProducts(id).ToList().Find(e => e.ClientID == id));
}
Reply
Answers (
3
)
cannot implicitily convert type bool to sysytem.data.dataset
auto display before 24 hours and after 24 hours