Why are you constantly turning IDENTITY_INSERT on and off (it's always on by default)?? This should normally be turned on and left alone. It should be turned off only for importing existing data, for example, during a migration of the database. This should not be done as normal course for inserting a record.
command.Connection = new SqlConnection(@"Data Source=JOHN-PC\SQLEXPRESS;Initial Catalog=subiect1;Integrated Security=True");
or something like that?
I repeat, i am new with C#. If someone knows and is willing to answer my questions, i will be very grateful. If they don't have anything useful to say, they are asked to keep their opinions for themselves.
On top of what Pete said, you don't need either of those IDENTITY_INSERT commands being executed. It appears you have no idea what they're for and are just copying and pasting code from the Internet without trying to understand what it does or why it's there.
And i inserted those commands because i got the error IDENTITY_INSERT is set off. So, what should i understand from that error? I thought i needed them, but i didn't know where i they are needed.I repeat, I've just put them there because of the error i received. How can i know it is wrong what i have done since i am new with c#?
This is the purpose of my question, people, to tell me what is wrong, not to receive reproaches. If i was smart enough, i didn't ask questions in forums, i would have solved my problem alone.
You're trying to insert an explicit value into an IDENTITY column[^]. The value of this column will normally be allocated by the database, which is why it gives you an error when you try to insert an explicit value.
In certain restricted cases, it is necessary to allow explicit values to be inserted into an identity column. This is the only time that IDENTITY_INSERT[^] is used. This should only be done as a maintenance operation, and not part of a normal insert.
If you want to insert explicit values into the column, then remove the identity property. Otherwise, don't specify the identity column in your INSERT statement.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
In which case just use some sort of algorithm that is applied to the ascii value of the first character, then use the output from this together with the value of the second character to convert the second character and so on(this way it is a little bit harder to crack the sequence of characters).
To decode it all you need to do is reverse the process starting from the first character again.
“That which can be asserted without evidence, can be dismissed without evidence.”
I need to encode a string to a 6 or 8 digits hash and decode it to original string
That is not possible. And it is proven as well.
Now if you want to take a string or binary data and create another string which will only contain alphanumerics then that is fairly easy. In most cases the second string will be longer than the first. You can look to Base64 encoding to see an example of how you might do this. (Base64 is similar to but not exactly the same as what the output you are asking for is.)
Hi, I have c# dll and I am using that dll in c++ with the help of COM Interop by importing the corresponding .tlb file in my .cpp file(#import "com.MyIntrop.tlb") and its working absolutely fine but now I want to use same dll in my C code but because I can not use #import in C how to use same dll which I have register as COM assembly in C.
The .tlb file is typically created by the MIDL.exe from the .idl source file. It has an option to generate .c/.h file to be used by C programs. But since you did not create the .tlb file (I assume it was auto-created by a tool), I don't think you can do much about it.
Here's a workaround. I'm not sure if it will work. You can use OleView.exe to reverse engineer the .tlb to .idl and then use MIDL.exe to compile the .idl back to .tlb with the option to generate .c/.h files. You can then use these files in your C program.
Thanks for the reply. I tried this, I have creted c++ dll anr I have wrapped c# dll in c++ dll but I am not able to load that c++ dll in C code. I used "LoadLibrary" function to load the dll but it didn't work and do we need to have .h file to load c++ dll?