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
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
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
Granted, I never worked with OleDB, Access, or Winforms
But this seems a little sus
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
I mean the other functions are still working. But I don't understand what it has to do with the saving record option?
I just told you
database want integer
you give string
string not integer
database angry
That's my best guess at least
But it is a integer
Far as I know,
TextBox.Text
is a string
Unless something changed in Winforms in recent yearsbut it should still work
Does it?
what could I do then?
should I change it from access to a string
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
It is already
what can I do then?
Show me how you pass proper types now
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 similarwhere then?
you said database
Oh for fuck's sake
In the CODE
that is the database
Your CODE gives the DATABASE a STRING
But the database wants NUMBER(
So GIVE NUMBER
Here
you mean Convert right?
Now it is a integer
i hop it is right
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?land is a string
datetimePicker1 is an reference to the date
Weird name for a variable that stores a date, but aight
I mean the program give it
I didn’t change the name
Ah, so it is a reference to the date picker
Not to an instance of
DateTime
Jeah, so what can I do?
Get the datetime from that picker?
There: command.Parameters.AddWithValue("@seit", Convert.ToDateTime(dateTimePicker1));
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
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?
Do you understand why a date picker is not a date?
Yes I do
Should be an easy fix, then
I have tried, but it isn't sill working
What have you tried?
I tried to get the datetime from this picker
How?
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.
Everything seems to be as it should be, then
Maybe you could link this thread in #database and ask for help there
okay thx
So what is your code as of now?
That's my code as of now.
Have you seen it?