C# Tutorial - Insert Update Delete Search data from local database | FoxLearn
Вставка
- Опубліковано 27 сер 2024
- Material Design Telephone Diary/Phone Book Insert Update Delete View and Search data from local database in C# using material skin. The C# Basics beginner course is a free C# Tutorial Series that helps beginning programmers learn the basics of the C# Programming Language
Website: foxlearn.com
insert update delete c# sql server
Insert Update Delete View and search data from database in C#.net
Fully C# Save, Insert, Update, Delete, View, Search, Clear in Visual studio
C# Insert Update Delete and View data from database in .net
Insert update delete select in c#
insert update delete data in database from datagridview
Update and Insert data in database from datagridview
Insert Update Delete and Search Data in local databases Using CSharp
how to fix this error message
cannot insert explicit value for identity column in table PhoneBooks when identity_insert is set to off
"Cannot insert explicit value for identity column in table 'PhoneBooks' when IDENTITY_INSERT is set to OFF"
I see a lot of people having the same problem, but I still don't understand the solution. Please explain in detail how to fix this. Thank you!
Solution that I found was updating the Identity Specification from FALSE to TRUE. The person does this at around the 6:39 mark. Dont know how I missed it.
I already checked the code, the mistake is that parameters you inserted on "string.format" are textboxes that shows the information, So you should use is the searching's textbox.
Nice work ! Would you please make more videos about local database print , how to add pictures thank you
It's almost great video, except few bugs. BUT i can't solve a problem with SAVING data. Also, I have allready solved problem with IDENTITY - just by putting string "appData.PhoneBooks.AcceptChanges();" after "phoneBooksBindingSource.EndEdit();"
BUT data is saving only in the Grid and don't saving in DataBase. After app restart - there are no data that I "saved".
HELP, please!
docs.microsoft.com/ru-ru/visualstudio/data-tools/save-data-back-to-the-database?view=vs-2019
I do not know if anyone still watches this but what worked for me for the "IDENTITY_INSERT is set to OFF" error is to simply rebuild the table adapter. It is a very easy process, just google it.
Thank you !
hi. could you tell me how? I cannot find the answer in google.. sorry
A great tutorial where I learned a lot.
First I forgot the AutoIncrement settings on the tables and the data was not saved. But I fixed that.
Now I always get the error "IDENTITY_INSERT is set to OFF".
I would be glad about a help.
Cannot insert sxplicit value for identity Column in Table … when IDENTITY_INSERT ist set to OFF
That's great. Thank you !
@@foxlearn : Can you help with the Problem: "Cannot insert explicit value for identity Column in Table … when IDENTITY_INSERT ist set to OFF" ? Can you please send me the Code t: dschmitz71@hotmail.com
followed the tutorial but keep getting the "cannot insert explicit value for identity column in table 'phonebooks' when IDENTITY_INSERT is set to OFF" any help?
For somereason after completly restarting visual stuidos everything started to work fine. Just incase someone needs help.
I have allready solved problem with IDENTITY - just by putting string "appData.PhoneBooks.AcceptChanges();" after "phoneBooksBindingSource.EndEdit();"
BUT data is saving only in the Grid and don't saving in DataBase. After app restart - there are no data that I "saved".
Hallo Fox Learn,
danke für deine super Videos, wirklich klasse wie du das alles zeigst.
Einen kleinen Tipp hätte ich aber - wie wäre es zum Teilen deine Programme Github zu benutzen? Das wäre für dich und deinen Zuschauern wesentlich einfacher. Außerdem müsste Visual Studio 2015 auch eine Github... haben. Also denke ich. :)
Gruß
Tobi
Thank you for your suggestion. I'm trying to build my website, i'll upload all in my site
Very informative and Great video. How to add a code for validating an existing record in database to avoid duplication of record. Thank you very much. Very new to the C# and learning by video.
Thank you !
@@foxlearn Welcome. Hoping soon for another informative tutorial
Hi, I would like to know how do I search multiple data, for example, If I have two entries by the name "Anna" and I would like to search for Anna,How do I Show both datas, because I am only able to show the first anna that the program searchs.
Wish there was more narrative and explanation 😉
Thanks for the video. But what is the purpose of materialskin?
also is there a way to validate if the record already exist to avoid duplication or record... tnx in advance
Hey! Can you show how to add a image in the database. Like I want to add an image with the contact info.
Your 'SEARCH' feature didnt work correctly. Also, you put in the CANCEL button but did nothing with it.
Hello, please i need your help if possible. I'm using one of your video for coding my app from datagrid using sql data base, and i want the same proprieties for one form i'm using as in this video but the code you used is adapted for a local database. How i can adapt it for sql please? i'll appreciate your help and thank you so much for sharing all this.
Hi, You can reference videos ua-cam.com/video/d4-DYhaGFvQ/v-deo.html , ua-cam.com/video/TRH7rm8ozD4/v-deo.html . Thank you
As usual nice work Fox, one of the posts in the past had a fix for PhoneBooks' when IDENTITY_INSERT is set to OFF I eventually tried it, it worked for me, I am not sure if it has affected any other part of the project. I have added an example below.
Ok just test and it looks like it is not saving to data bass.
private void btnSave_Click(object sender, EventArgs e)
{
try
{
Edit(false);
phoneBooksBindingSource.EndEdit();
phoneBooksTableAdapter.Update(appData.PhoneBooks);
dataGridView.Refresh();
txtPhoneNumber.Focus();
MessageBox.Show("Your data has been successfully saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
appData.MemberDetails.RejectChanges();
}
}
Ok just test after posting and it looks like it is not saving to the data base.
You should copy your database to another folder. Each time you rebuild your project all data in debug folder will be deleted.
@@foxlearn I have not rebuilt since I finished, I am now trying to use and it will not save. I click NEW then add details and then click SAVE I can add many customers ID to list but as I exit the form and open it again the data is not there
i am having an issue when i trying to run the .exe of the published program. i get an sql error when running the program on another computer..
is it possible to do it in excel instead of access??
How to fix Cannot insert explicit value for identity column when set identity off
Do you have the code?
Hi, You should set identity on. Please try again
how to set identity on please?
i have problem Cannot insert explicit value for identity
I also have that problem... What should i do to solve it?
You can set it yourself here 6:30
What do you use for a Data Time? I have problems with that. Thanks.
Hi, what error are you getting ?thanks
Awesome video, very informative and well done. And if I want to install the application in another pc, how can I do that? (it threw me an error)
OK. Thank you for your suggestion. I'll make the tutorial on this as soon as possible !
Fox Learn Thanks dude, you have a great channel, subscribed!
datagrid is not being refreshed...why? pls help me...I used same code and form
Please review your code, has you noticed that it didn't search the information you typed in.
Can you please check again the code? Great Video thanks a lot!!!
Hi, What's your email? thanks
Hi, ing_mecandres@hotmail.com thanks
Sent. Thank you !
Hello, when I use commands like phoneBooksTableAdapter.Update(appData.PhoneBooks) or Message.Show(....) I get errors. For example in the Message case I get " 'Message' does not contain a definition for 'Show' ". What is wrong??
Hi, You need create windows form project, check your reference to System.Windows.Form
oswm vedio ...but i have a errror would help me .? the error is
Cannot insert explicit value for identity column in table 'PhoneBook' when IDENTITY_INSERT is set to OFF.......first time i am using this mathod,,,,
change your target frame work to ".NET Frame 4.5.1
Sorry but don't save into to database, when I restart....
Search functionality not working properly it always shows the first row,can anyone help me for this
Hello,
I need your help.
after searching for the required string, my database does not come to its original position.
How to fix it?
thank you in advance .
Please try to set position to bindingsource. Thank you !
I keep getting same error message when trying to save datas "cannot insert explicit value for identity column in table 'phonebooks' when IDENTITY_INSERT is set to OFF". I really don't know what is the problem. I did exactly as it is in the video. I even tried switching from true to false and nothing really happens. Pls help!
Hi, You need to set identity for primary key and the table in your dataset should set auto number is true. please try again. Thanks
I'm getting lots of errors refering to Form1.Designer.cs (Designer window display those errors) and also I'm getting error about AppData that there is no type or namespace like AppData.
Does anyone knows how to solve those problems?
HI guys, i managed to solve the Insert Identity issue. Please click on the "dbo.PhoneBooks" plane and under properties switch Identity Column to "Id"
hello can i ask what if i want add a delete button ? what is the source code :-) .newbie here
thank you 1000/1000
You're welcome !
I have done the same steps as you have shown in the window but still, when I click new and fill the details, they are not shown in the DataGridview. Also, when I again press new there comes an error message "Column id cannot be null".
Try to open your dataset, then set the id column to autonumber
@@foxlearn Sir i have also the same problem error that occurs -->>Column id cannot be null. and i have also try to solve but i don't get options to set the id column to autonumber
hello ,can help me after the end project how insert to other computer and working .??...thank you fox learn
You only need change your connection string in the app.config file
Your have any vidoes About this ??
Hi, foxlearn how can I check from a database for logining like it check if user exists and is it a right password so he could login
ua-cam.com/video/4ToxRR-zlKs/v-deo.html .You can view this video. thank you !
Is it possible you could go trough adding delete on this ?
What do you mean? Can you describe more details? Thank you
Thank u
Thanks :)
what if, add open location?
My material toolbox doesn't appear
Hello guys i have an error when i can try to insert a data to database.
Error message is cannot insert explicit value for identity column in table Identity_insert is set to off
How can i fix it?
Thanks for your help :)
Hi, You need to set id column is primary key and set identity. insert data you don't need add id column it's auto genereate. thanks
Столкнулся с проблемой. Сделал все как описано на одной машине (Windows 7 Visual Studio 2010) - все работает. Как только перенес на другую машину (Windows XP Visual Studio 2010) сразу выдало, что невозможно вставить явное значение для столбца идентификаторов, когда IDENTITY_INSERT в положении OFF. Как быть? Куда, что или где переключить чтобы все заработало вновь?
Hi, I you should set id is auto number, copy to another computer your database structure don't change. please check again. thank you so much !
Hi Fox, I have tried most of the solutions from the comments in posts the closest I get is a solution for a post but it still won't save to database do you have any other ideas. once I close the form and restart the form data is gone. on this example, the only changes I am using is memberDetails instead of phoneBooks and adding appData.MemberDetails.AcceptChanges();
private void btnSave_Click(object sender, EventArgs e)
{
try
{
Edit(false);
memberDetailsBindingSource.EndEdit(); appData.MemberDetails.AcceptChanges(); //edited
memberDetailsTableAdapter.Update(appData.MemberDetails);
dataGridView.Refresh();
txtPhoneNumber.Focus();
MessageBox.Show("Your data has been successfully saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
appData.MemberDetails.RejectChanges();
}
}
Андрей И.
1 year ago (edited)
It's almost great video, except few bugs. BUT i can't solve a problem with SAVING data. Also, I have allready solved problem with IDENTITY - just by putting string "appData.PhoneBooks.AcceptChanges();" after "phoneBooksBindingSource.EndEdit();"
BUT data is saving only in the Grid and don't saving in DataBase. After app restart - there are no data that I "saved".
HELP, please!
You should copy your database to another folder, by default your database copy to debug folder. Each time you rebuild your project all files in debug folder will be deleted.
+Fox Learn is C# and Windows C# programming same you do windows
Hi, C# is a programming language. With desktop application you can use C# Windows Forms. Thanks
No i know that but codes are same
i know that but the codes are same of c# windows programming and c# simple programming or not i am asking
I have follow step by step but cant save any data in my program/database pls anyone help me
How can i fix "Cannot insert explicit value for identity column when set identity off" Please help
Hi, I think you need to set identity is true, please check your id column again, Thank you
hi i want to add the data inside gridview like items and subitem can you please send the code
OK. Thank you for your suggestion. I'll make soon
The cancel button is unused, and the search is not working correctly in your video. Bad tutorial, in my opinion.
Please help me. when i click 'NEW' old record is not cleared
Hi, You need to add new object to bindingsource, please check your code again. thanks
If you observe the code you will see that when looking for some data you do not get what you are really looking for, but the first row of the datagrid. How can you fix that part of the code? , can you send me the code, thk
What's your email? thank you
amor-mariano@hotmail.com
I found a way with Button Click
private void btn_Search_Click(object sender, EventArgs e)
{
string searchValue = txt_Search.Text;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
phoneBooksBindingSource.Filter = string.Format("{0} = '{1}'", "FullName", searchValue);
//here you can do selection if you need
}
}
}
could you please mention more cool themes. thanks!
Hi, You can use Metro Framework. Thanks
I know it and have used it, I mean if there are more themes... Thanks!!
My search does not work, i did equals the video, has somebody with this problemas?
Same, can't get it to work. Looking right now, let me know if you find something.
I found a way with Button Click
private void btn_Search_Click(object sender, EventArgs e)
{
string searchValue = txt_Search.Text;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
phoneBooksBindingSource.Filter = string.Format("{0} = '{1}'", "FullName", searchValue);
//here you can do selection if you need
}
}
}
Thank you very much, I was struggling, you saved my life!
but how to get back the whole list again?
Won't let me add a reference to the material's toolbox
Hi, You can view this video: ua-cam.com/video/QdMXWyvKamE/v-deo.html, thanks
i cant get the material single line text box how can i fix this
Hi, You can view this video ua-cam.com/video/QdMXWyvKamE/v-deo.html to know to to install and add material skin to your toolbox, then you can find single line text box in your toolbox. . Thank you
how to add material skin controls to toolbox?
Hi, You can view this video ua-cam.com/video/QdMXWyvKamE/v-deo.html to know how to install and add material skin to your toolbox. Thank you
i got an error says "the type name AppData Does Not exist in the type name "my project name" "
please help
problem solved by changing the class name into another
That's great, the AppData is name of the DataSet, you can put any name :)
Hi this really helpful video but i always fault when tryin to save data in mu database, when i ran my program and click new it always said phonenumber cannot null and the main problem is when i have to fill all the txt and click save the database is not inserted it only show the message box "data has been successfully saved!" Please someone help me, im a newbie and really need it :(
+Dewi Cunny so sad to hear this happened to you, anyway i still stuck in this problem, but if you cant show the messagebox it really wierd, have you type --> MessageBox.Show("your Message","Message",MessageBoxbutton.OK,MessageBoxIcon.Information); ? If you write that line and still have error maybe the problem is with your visual studio
happy that you solved it, for search funciton i think the tutorial was doing right just follow this video and makesure you dont miss anything (ya sometimes is not well explained). anyway what you do to input and save your data into the database? i still stuck with this problem for a couple of months
that mean you make new savebutton_click method and solved your problem? where you got that code?
thank you you are so kind :)
i don't know what should i do coz i also create new and follow it again again and again but the problem is the same
were u able to get your data after clicking 'Save'? my data is not showing..but it says that data has been inserted successfully.
why arabic characters become question marks
in the dataGridView
Hi, I think you should save data with nvarchar instead of varchar, Please check your datatype again. Thank you
thanks, it worked.
hi I want print option with adding logo can you please send me a source code
Hi, What's your email? thank you
i got another error when saving the data says "cannot insert explicit value for identity column in table 'phonebooks' when IDENTITY_INSERT is set to OFF "
Hi, You need to set the identity column is auto number both table in dataset, and table in your database, please try again. thanks
+Fox Learn ok i'll give it a shot, it works by setting the identity column to false but i need it to be auto so i'll try.
Thanks alot
I am also getting this error. Help me how i resolve it.
Jamal Rizvi Hi, you can resolve this problem by setting the id column identity from true to false
Thanks dear. Now record has been saved successfully. But when i click 'NEW' old record is not cleared
Почему сразу не сохраняет т.е. вышел из формы и информация пропала
What information are you missing?
Запуск из Visual Studio, а не на прямую .exe При каждой компиляции сборки, данные исчезают, с чем связано ?
How to use for search the button?
Hi, You can add a button search, then copy code even key press to button click, thanks
I found a way with Button Click
private void btn_Search_Click(object sender, EventArgs e)
{
string searchValue = txt_Search.Text;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
phoneBooksBindingSource.Filter = string.Format("{0} = '{1}'", "FullName", searchValue);
//here you can do selection if you need
}
}
}
Can you send me the code
can anyone send me this code
?
Can you kindly send me the code?
I'm stuck at one part.
Hi, What's your email? thanks
taufiqrx8@gmail.com
thanks in advance! :)
+Fox Learn
Sent. Thanks
Can you please send me the code at alisalman668@gmail.com. Its urgent. I will be thankful to you bro
y el maldito codigo he ? esa mierda me da error
could you send me source code for this project
Hi, What's your email ? Thank you
sylhoumel@gmail.com
send me the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MaterialSkin;
namespace Forma
{
public partial class Form1 : MaterialSkin.Controls.MaterialForm
{
public Form1()
{
InitializeComponent();
var skinManager = MaterialSkinManager.Instance;
skinManager.AddFormToManage(this);
skinManager.Theme = MaterialSkinManager.Themes.DARK;
skinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500,Accent.LightBlue200,TextShade.WHITE);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: данная строка кода позволяет загрузить данные в таблицу "appData.Sport". При необходимости она может быть перемещена или удалена.
this.sportTableAdapter.Fill(this.appData.Sport);
Edit(false);
}
private void Edit(bool value)
{
txtPhoneNumber.Enabled = value;
txtFullName.Enabled = value;
txtEmail.Enabled = value;
txtAdress.Enabled = value;
}
private void btnNew_Click(object sender, EventArgs e)
{
try
{
Edit(true);
appData.Sport.AddSportRow(appData.Sport.NewSportRow());
sportBindingSource.MoveLast();
txtPhoneNumber.Focus();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Оповещение", MessageBoxButtons.OK, MessageBoxIcon.Error);
appData.Sport.RejectChanges();
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
Edit(true);
txtPhoneNumber.Focus();
}
private void btnCancel_Click(object sender, EventArgs e)
{
Edit(false);
sportBindingSource.ResetBindings(false);
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
Edit(false);
sportBindingSource.EndEdit();
sportTableAdapter.Update(appData.Sport);
dataGridView.Refresh();
txtPhoneNumber.Focus();
MessageBox.Show("Cохранить запись запись?", "Оповещение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Оповещение", MessageBoxButtons.OK, MessageBoxIcon.Error);
appData.Sport.RejectChanges();
}
}
private void txtSeach_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (!string.IsNullOrEmpty(txtSeach.Text))
sportBindingSource.Filter = string.Format("PhoneNumber = '{0}' OR FullName LIKE '*{1}*' OR Email ='{2}' OR Adress LIKE '*{3}*'", txtPhoneNumber.Text,txtFullName.Text,txtEmail.Text,txtAdress.Text);
else
sportBindingSource.Filter = string.Empty;
}
}
private void dataGridView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
if (MessageBox.Show("Вы Уверена что хотите удалить запись ?", "Оповещение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) ;
sportBindingSource.RemoveCurrent();
}
}
}
}
Здравствуйте, спасибо большое за видео! Но не могу разобраться как сделать поиск, а у вас там ошибочка ( можете пожалуйста прислать код на почту anksunamun-99@mail.ru
please sent me too :)
kaifahmed0341@gmail.com
Not sure using an extremely fast, unclear AI voice was the best idea in a tutorial, and I think you could've explained what you were doing as opposed to having that AI voice giving a speedy background narration. Get's a dislike from me.
Thank you for your suggestion, I'll try to better :(
u very eng ,send me code
plaes
Sent, Please check your email. Thank you
Fox Learn alabadan.market@gmail.com