Overlaping of the record when Inserting the Record problem for the ID which is auto in Identity set

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal I try to Insert the record with images it it but problem is that i built the Database with Identity set to true means the ID is auto selected but my program in C# i
built the program that it for manual ID mean user enter the ID which is not right because i set the Identity as true which is incremented with 1 started with 100 . Due to this reason i got the error i try to solve it but i cant . When i try to enter the record
as<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<img alt="" height="435" src="http://www.eggheadcafe.com/FileUpload/1898367381/Pic.JPG" width="744" style="border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal Then the Error is like that and Yes i try to not enter the StudentID mean leave as blank then error is also occur which tell Column StudentID is constrained to be
unique. Value is already present. how to solve this problem without touching the Identity which is incremented by one and started with 100 . Tell me please. <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<img alt="" height="452" src="http://www.eggheadcafe.com/FileUpload/1898367381/Image2.JPG" width="738" style="border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal My AddModifyStudentRecords : Form Code is <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal DataSet StudentTrackerDataSet;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal DataRow currentRow;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal private DataSet StudentTrackerDataset;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal public AddModifyStudentRecords()<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal {<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal InitializeComponent();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal }<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal // create two constructores One of these accept the Dataset as parameters and Other will be <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal // other will accept the DataSet and Datarow as the parameter<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal public AddModifyStudentRecords(DataSet ds)<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal {<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal InitializeComponent();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal StudentTrackerDataSet = ds;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow = null;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal }<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal public AddModifyStudentRecords(DataSet ds, DataRow row)<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal {<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal InitializeComponent();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal StudentTrackerDataSet = ds;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal textBox1.Text =currentRow["StudentID"] .ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal textBox2.Text = currentRow["FirstName"].ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal textBox4.Text = currentRow["LastName"].ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal textBox3.Text = currentRow["Gender"].ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal textBox5.Text = currentRow["GPA"].ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal txtBrowseFile.Text = currentRow["MyImage"].ToString ();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal byte[] data = (byte[])currentRow ["MyImage"];<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal MemoryStream ms = new MemoryStream(data);<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal pictureBox1.Image = Image.FromStream(ms);<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal }<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal private void label3_Click(object sender, EventArgs e)<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal {<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal }<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal private void button2_Click(object sender, EventArgs e)<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal {<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal string StudentID = textBox1.Text.ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal string StudentFirstName = textBox2.Text.ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal string StudentLastName = textBox4.Text.ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal string Gender = textBox3.Text.ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal string GPA = textBox5.Text.ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal Image MyImage = pictureBox1.Image;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal DataTable table = StudentTrackerDataSet.Tables["Student"];<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal if (currentRow == null)<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal {<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow = table.NewRow();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow["StudentID"] = textBox1.Text.ToString();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal table.Rows.Add(currentRow );<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal }<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow .BeginEdit();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow ["StudentID" ]=StudentID ;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow["FirstName"] = StudentFirstName;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow["LastName"] = StudentLastName;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow["Gender"] = Gender;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow["GPA"] = GPA;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow["MyImage"] = convertToByte(txtBrowseFile.Text); <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal currentRow.EndEdit();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal Close();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal }<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal byte[] convertToByte(string sourcePath)<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal { //get byte file size of image<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal FileInfo FInfo = new FileInfo(sourcePath);<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal long sizeByte = FInfo.Length;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal // read the File uisng file stream<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal FileStream fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read);<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal // read it agian as the byte using binary reader <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal BinaryReader br = new BinaryReader(fs);<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal // convert image to byte already <br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal byte[] data = br.ReadBytes((int)sizeByte);<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal return data;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal }<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal private void button1_Click(object sender, EventArgs e)<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal {<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal Close();<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal }<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal private void button3_Click(object sender, EventArgs e)<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal {<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal if (openFileDialog1.ShowDialog() == DialogResult.OK)<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal {<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal txtBrowseFile.Text = Path.GetFullPath(openFileDialog1.FileName);<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal pictureBox1.ImageLocation = txtBrowseFile.Text;<br style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal
<span style="color:#636363; font-family:Segoe UI; font-size:13px; line-height:normal }

View the full article
 
Back
Top