Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Using sqlcommand datareader not working sending back to json ajax

$
0
0

Decided to use sql in mvc to write the select with the variables for tablename not known until runtime.  This is not returning to json what is wrong with this. 

  using (SqlConnection connection = new SqlConnection("test")            {

                SqlCommand command = new SqlCommand();
                command.CommandText = @"Select Organization from " + tablename + " df join Signature sg on sg.FormInstanceId = df.FormInstanceId where sg.FullName = '" + who + "'";
                command.CommandType = CommandType.Text;

                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                // Call Read before accessing data.
                while (reader.Read())
                {

                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        var subject = reader.GetString(3);
                        result.Add(subject);
                    }

                }


            }



            return Json(result, JsonRequestBehavior.AllowGet);


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>