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
Adesanya Olusegun
NA
19
26.7k
Binding Data to a grid view
Feb 16 2014 6:20 PM
this code below gives me an error DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'CourseName'. am hoping to get a solution to it thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class CourseRegistration : System.Web.UI.Page
{
Connector newconnect = new Connector();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Student"] != null)
{
try
{
string matricno = Session["Student"].ToString();
if (!IsPostBack)
{
GridView1.DataSource = GetData("select CourseRegistration.CourseCode, CoursesTable.CourseName, CoursesTable.CourseUnit from (DepartmentTable inner join CoursesTable on DepartmentTable.DepartmentID=CoursesTable.DepartmentID) inner join CourseRegistration on CoursesTable.CourseCode = CourseRegistration.CourseCode where MatricNo = '" + matricno + "'");
GridView1.DataBind();
}
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
}
private DataSet GetData(string query)
{
string matricno = Session["Student"].ToString();
string conString = ConfigurationManager.ConnectionStrings["OnlineExamination_String"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds;
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string matricno = Session["Student"].ToString();
SqlCommand command = new SqlCommand();
command = newconnect.HelpCommand("CourseChecker");
command.Parameters.AddWithValue("@MatricNo", matricno);
command.Parameters.AddWithValue("@CourseCode", DropDownList3.SelectedValue);
SqlDataReader rv = command.ExecuteReader();
if (rv.HasRows == false)
{
try
{
SqlCommand commander = new SqlCommand();
commander = newconnect.HelpCommand("CourseRegInsert");
commander.Parameters.AddWithValue("@MatricNo", matricno);
commander.Parameters.AddWithValue("@CourseCode", DropDownList3.SelectedValue);
commander.Parameters.AddWithValue("@Session", DropDownList4.SelectedValue);
commander.ExecuteNonQuery();
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
else
{
}
}
}
Reply
Answers (
0
)
Word prediction using n-gram technique
Store Zip file in Database