Error =Child list for field Student cannot be created for imagecolumn Imaglayout stretch

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="padding-right:0px; font-family:Segoe UI; font-size:13px; line-height:normal; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; border-width:initial; border-color:initial; list-style-type:none; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none
<span style="white-space:pre-wrap; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<p style="padding-right:0px; font-family:Segoe UI; font-size:13px; line-height:normal; border-style:initial; border-color:initial; outline-width:0px; outline-style:initial; outline-color:initial; border-width:initial; border-color:initial; list-style-type:none; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none
<span style="white-space:pre-wrap; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px I want to retrieve the Record with Imagecolumn also and also want to stretch the
<span style="color:#333333 <span style="line-height:16px Imagelayout for one example i was got success but for other i have problem and error is rise which is error=<span style="font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif Child
list for field Student cannot be created .please help me about this topic i will very thank full to you all my friends my EggheadhCafe friends <br/>

<p style="padding-right:0px; border-style:initial; border-color:initial; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; border-width:initial; border-color:initial; list-style-type:none; color:#333333; line-height:16px; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none
public sealed class DAC<br/>
{<br/>
// Create Class variabl <br/>
private static SqlDataAdapter StudentDataAdapter = CreateSutdentDataAdapter();<br/>
public static SqlDataReader GetCompanyInformation()<br/>
{<br/>
SqlDataReader reader;<br/>
string sql = "SELECT * FROM Student ";<br/>
using (SqlCommand command = new SqlCommand(sql, ConnectionManager.GetConnection()))<br/>
{<br/>
reader = command.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.CloseConnection);<br/>
}<br/>
return reader;<br/>
}<br/>
// Creat the Data Addapter <br/>
private static SqlDataAdapter CreateSutdentDataAdapter()<br/>
{<br/>
// Create the Select Statement and create Insert Update and Delete query <br/>
string gettSQL = "SELECT * FROM Student";<br/>
string insertSQL = "INSERT INTO Sutdent(StudentID, FirstName,LastName,Gender,GPA,MyImage)" +<br/>
"VALUES (@StudentID,@FirstName,@LastName,@Gender.@GPA,@MyImage)";<br/>
string updateSQL = "UPDATE Student SET StudentName=@StudentName, LastName=@LastName,Gender=@Gender,GPA=@GPA, MyImage=@MyImage";<br/>
string deleteSQL = "DELETE FROM Student WHERE StudentID=@StudentID";<br/>
// For Lager Programing (DATABASE) using StorProceduer not the string type <br/>
// Now create the SQLDATAAdapeter<br/>
SqlDataAdapter dataAdapter = new SqlDataAdapter();<br/>
// now Create the DataAdapter to Poputlate our GridView or DisconnectedDataset using SqlCommand<br/>
// In SelectCommand passing SQlCommand and in SQlCommand passing to varaible namely string sql query and the Connection of the Database <br/>
dataAdapter.SelectCommand = new SqlCommand(gettSQL, ConnectionManager.GetConnection());<br/>
//now in same way create the InsertCommand also <br/>
dataAdapter.InsertCommand = new SqlCommand(insertSQL, ConnectionManager.GetConnection());<br/>
// Create or Add the Parameter of th dataAdapter for InsertCommand <br/>
dataAdapter.InsertCommand.Parameters.Add("@StudentID", SqlDbType.Int).SourceColumn = "StudentID";<br/>
dataAdapter.InsertCommand.Parameters.Add("@FirstName", SqlDbType.VarChar,25 ).SourceColumn = "FirstName";<br/>
dataAdapter.InsertCommand.Parameters.Add("@LastName", SqlDbType.VarChar, 25 ).SourceColumn = "LastName";<br/>
dataAdapter.InsertCommand.Parameters.Add("@Gender", SqlDbType.VarChar ,1).SourceColumn = "Gender";<br/>
dataAdapter.InsertCommand.Parameters.Add("@GPA", SqlDbType.Float ).SourceColumn = "GPA";<br/>
dataAdapter.InsertCommand.Parameters.Add("@MyImage", SqlDbType.VarBinary).SourceColumn = "MyImage";<br/>
//Create the UpdateCommand and the Parameters<br/>
dataAdapter.UpdateCommand = new SqlCommand(updateSQL, ConnectionManager.GetConnection());<br/>
dataAdapter.UpdateCommand.Parameters.Add("@StudentID", SqlDbType.Int).SourceColumn = "StudentID";<br/>
dataAdapter.UpdateCommand.Parameters.Add("@FirstName", SqlDbType.VarChar,25 ).SourceColumn = "FirstName";<br/>
dataAdapter.UpdateCommand.Parameters.Add("@LastName", SqlDbType.VarChar, 25 ).SourceColumn = "LastName";<br/>
dataAdapter.UpdateCommand.Parameters.Add("@Gender", SqlDbType.VarChar ,1).SourceColumn = "Gender";<br/>
dataAdapter.UpdateCommand.Parameters.Add("@GPA", SqlDbType.Float ).SourceColumn = "GPA";<br/>
dataAdapter.UpdateCommand.Parameters.Add("@MyImage", SqlDbType.VarBinary).SourceColumn = "MyImage";<br/>
dataAdapter.DeleteCommand = new SqlCommand(deleteSQL, ConnectionManager.GetConnection());<br/>
dataAdapter.DeleteCommand.Parameters.Add("@StudentID", SqlDbType.Int).SourceColumn = "StudentID";<br/>
// last return dataAdapter<br/>
return dataAdapter;<br/>
}<br/>
// Creating the Table Schima <br/>
private static void DefinestudentTableSchema(DataTable table)<br/>
{<br/>
DataColumn StudentIDColumn = table.Columns.Add("StudentID", typeof(string));<br/>
StudentIDColumn.AllowDBNull = false;<br/>
table.PrimaryKey = new DataColumn[] { StudentIDColumn };<br/>
DataColumn StudentFirstName = table.Columns.Add("FirstName", typeof(string));<br/>
StudentFirstName.MaxLength = 150;<br/>
DataColumn StudentLastName = table.Columns.Add("LastName", typeof(string));<br/>
StudentLastName.MaxLength = 150;<br/>
DataColumn StudentGender = table.Columns.Add("Gender", typeof(char));<br/>
//StudentGender.MaxLength = 10;<br/>
DataColumn StudentGPA = table.Columns.Add("GPA", typeof(float));<br/>
DataColumn StudentImage = table.Columns.Add("MyImage", typeof(Byte[]));<br/>
//Create the DataSet<br/>
}<br/>
private static DataSet CreateStudentTrackerDataSet()<br/>
{<br/>
DataSet StudentTrackerDataSet = new DataSet();<br/>
DataTable StudentTable = StudentTrackerDataSet.Tables.Add("Student");<br/>
DefinestudentTableSchema(StudentTable);<br/>
return StudentTrackerDataSet;<br/>
}<br/>
//GetDataFunction that Populat the Gridview <br/>
public static DataSet GetData()<br/>
{<br/>
DataSet StudentTrakerDataSet = CreateStudentTrackerDataSet();<br/>
StudentTrakerDataSet.EnforceConstraints = false;<br/>
StudentDataAdapter.Fill(StudentTrakerDataSet.Tables["Student"]);<br/>
StudentTrakerDataSet.EnforceConstraints = true;<br/>
return StudentTrakerDataSet;<br/>
}
<p style="padding-right:0px; border-style:initial; border-color:initial; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; border-width:initial; border-color:initial; list-style-type:none; color:#333333; line-height:16px; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none
And my .CS Code is
<p style="padding-right:0px; border-style:initial; border-color:initial; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; border-width:initial; border-color:initial; list-style-type:none; color:#333333; line-height:16px; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none
public partial class AditStudent : Form<br/>
{<br/>
// Creat the Class variabl Dataset to track the Student<br/>
private DataSet StudentTrackerDataset;<br/>
public AditStudent()<br/>
{<br/>
InitializeComponent();<br/>
// In the constructor of the AditStudent form we are puting the DataEvenhandler<br/>
dataGridView1.DataError += DataGridView1_DataError;<br/>
StudentTrackerDataset = ProjectOfSchool.DataAccessLayer.DAC.GetData();
<p style="padding-right:0px; border-style:initial; border-color:initial; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; border-width:initial; border-color:initial; list-style-type:none; color:#333333; line-height:16px; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none
// Problem is at here which tell us that Child list for field Student cannot be created.
<p style="padding-right:0px; border-style:initial; border-color:initial; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; border-width:initial; border-color:initial; list-style-type:none; color:#333333; line-height:16px; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none
dataGridView1.DataMember = "Student";<br/>
for (int i = 0; i < dataGridView1.Columns.Count; i++)<br/>
if (dataGridView1.Columns is DataGridViewImageColumn)<br/>
{<br/>
((DataGridViewImageColumn)dataGridView1.Columns).ImageLayout = DataGridViewImageCellLayout.Stretch;<br/>
break;}
<p style="padding-right:0px; border-style:initial; border-color:initial; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; border-width:initial; border-color:initial; list-style-type:none; color:#333333; line-height:16px; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none
DataTable StudentTable = StudentTrackerDataset.Tables["School"];<br/>
dataGridView1.DataSource = StudentTable;<br/>
}<br/>
private void DataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)<br/>
{<br/>
// creating DataErrorHandler and methods of Datagridview1<br/>
// string meassage by string farmaating to show how the error will look like for the Error in the Datagrid in from columan 0 and in row 1:2 multidimintional array type <br/>
string message = string.Format("Error in {0} columan in row {1}:{2}", e.ColumnIndex, e.RowIndex, e.Exception.Message);<br/>
// now show the Error using messagebox <br/>
MessageBox.Show(message, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);<br/>
}
<p style="padding-right:0px; border-style:initial; border-color:initial; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; border-width:initial; border-color:initial; list-style-type:none; color:#333333; line-height:16px; border-top-style:none; border-right-style:none; border-bottom-style:none; border-left-style:none
Error is that When i run the form then Child list for field Student cannot be created. is shown . And Yes in same way when i display the record using this code like
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px then no error and record is shown as i required Please tell me about how to fix this problem my friend <br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px string sql = "SELECT * FROM Student";<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px using (SqlCommand Command = new SqlCommand(sql, ProjectOfSchool.DataAccessLayer.ConnectionManager.GetConnection()))<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px {<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px SqlDataAdapter ds = new SqlDataAdapter();<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px ds.SelectCommand = Command;<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px DataSet Ds = new DataSet();<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px ds.Fill(Ds, "Student");<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px dataGridView1.DataSource = Ds;<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px dataGridView1.DataMember = "Student";<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px for (int i = 0; i < dataGridView1.Columns.Count; i++)<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px if (dataGridView1.Columns is DataGridViewImageColumn)<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px {<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px ((DataGridViewImageColumn)dataGridView1.Columns).ImageLayout
= DataGridViewImageCellLayout.Stretch;<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px break;<br style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px
<span style="font-size:13px; color:#333333; font-family:segoe ui,lucida grande,verdana,arial,helvetica,sans-serif; line-height:16px }
<h2 style="font-size:10pt; padding-bottom:0px; margin-bottom:0px; font-family:Segoe UI; line-height:normal
I am waiting for replay of my MSDN friends please help me about this error i will be very thank full to all my MSDN friends and special thanks to MSDN team

View the full article
 
Back
Top