C
C#5mo ago
Masher.

Ensure that the records stay saved for the database

Could anyone help me at that example of a Insert, Update, Delete & Search Operation in C# with MS-Access Database? I want to make sure that everything gets from the database saved when I have made a change. Code:
50 Replies
Angius
Angius5mo ago
Oh boy, Access... Generally speaking, though... if you executed a query that saves something, and the execution did not throw an exception, it is safe to assume that it was saved
Masher.
Masher.OP5mo ago
The problem is there is no exception that shows me a mistake. That's why im asking If I have made a change in the datagridview then it doesn't save anything
Angius
Angius5mo ago
Granted, I never worked with OleDB, Access, or Winforms
Angius
Angius5mo ago
But this seems a little sus
No description
Angius
Angius5mo ago
Inserting a string where an integer should go? Would not surprise me if Ole just surrounded it with strings And if the database expects an integer... ...assuming Access can even make such expectations... ...it would cause an error
Masher.
Masher.OP5mo ago
I mean the other functions are still working. But I don't understand what it has to do with the saving record option?
Angius
Angius5mo ago
I just told you database want integer you give string string not integer database angry That's my best guess at least
Masher.
Masher.OP5mo ago
But it is a integer
Angius
Angius5mo ago
Far as I know, TextBox.Text is a string Unless something changed in Winforms in recent years
Masher.
Masher.OP5mo ago
but it should still work
Angius
Angius5mo ago
Does it?
Masher.
Masher.OP5mo ago
what could I do then? should I change it from access to a string
Angius
Angius5mo ago
Huh? Change from a database to a C# type? That... makes little sense Very little "None", one could say No, just make sure you give proper types If a field in the database is an integer, make sure that the parameter you pass there is an integer
Masher.
Masher.OP5mo ago
It is already what can I do then?
Angius
Angius5mo ago
Show me how you pass proper types now
Masher.
Masher.OP5mo ago
No description
Angius
Angius5mo ago
In the database, yes Not here What you bind to @KID is a STRING What the database wants there is a ZAHL Which, I assume, stands for INTEGER, or NUMBER or something similar
Masher.
Masher.OP5mo ago
where then? you said database
Angius
Angius5mo ago
Oh for fuck's sake In the CODE
Masher.
Masher.OP5mo ago
that is the database
Angius
Angius5mo ago
Your CODE gives the DATABASE a STRING But the database wants NUMBER( So GIVE NUMBER
Angius
Angius5mo ago
No description
Angius
Angius5mo ago
Here
Masher.
Masher.OP5mo ago
you mean Convert right?
Masher.
Masher.OP5mo ago
No description
Masher.
Masher.OP5mo ago
Now it is a integer i hop it is right
Angius
Angius5mo ago
No description
Angius
Angius5mo ago
Not the ideal way to convert, but sure Yes, now it is integer Now find other zahls And ensure they also get the proper data type I see that seit also wants a date, or a DateTime. Is dateTimePicker1 an instance of a DateTime, or is it a reference to the date picker itself? Similarly, is land a string?
Masher.
Masher.OP5mo ago
land is a string datetimePicker1 is an reference to the date
Angius
Angius5mo ago
Weird name for a variable that stores a date, but aight
Masher.
Masher.OP5mo ago
I mean the program give it I didn’t change the name
Angius
Angius5mo ago
Ah, so it is a reference to the date picker Not to an instance of DateTime
Masher.
Masher.OP5mo ago
Jeah, so what can I do?
Angius
Angius5mo ago
Get the datetime from that picker?
Masher.
Masher.OP5mo ago
There: command.Parameters.AddWithValue("@seit", Convert.ToDateTime(dateTimePicker1));
Angius
Angius5mo ago
No, I don't think it works that way My advice: learn how C# works on some basic projects first You seem to have no idea about what the type system is, and that's like the basic requirement Then learn Winforms — if you really want to use it — from some course or a tutorial
Masher.
Masher.OP5mo ago
I have already tried it with a tutorial and then I started to do the same thing on my project After that, I found out that it wasn't working how I expected Hey, sorry if I am interrupting, but I do understand now the type system and I have also worked with some basic projects Could you explain me now how I could fix the problem?
Angius
Angius5mo ago
Do you understand why a date picker is not a date?
Masher.
Masher.OP5mo ago
Yes I do
Angius
Angius5mo ago
Should be an easy fix, then
Masher.
Masher.OP5mo ago
I have tried, but it isn't sill working
Angius
Angius5mo ago
What have you tried?
Masher.
Masher.OP5mo ago
I tried to get the datetime from this picker
Angius
Angius5mo ago
How?
Masher.
Masher.OP5mo ago
I have used the Value property of the DateTimePicker to get the DateTime value and assign it to the @seit parameter in the sql query.
Angius
Angius5mo ago
Everything seems to be as it should be, then Maybe you could link this thread in #database and ask for help there
Masher.
Masher.OP5mo ago
okay thx
❤RieBi&❤
❤RieBi&❤5mo ago
So what is your code as of now?
Masher.
Masher.OP5mo ago
That's my code as of now.
Masher.
Masher.OP5mo ago
Have you seen it?
Want results from more Discord servers?
Add your server