|
Seems the easier approach would be to import Access tables directly into Sql Server using an "import" task in management studio. It creates the necessary tables.
Your "data conversion app" can then target the imported SQL Server tables without mucking with Access (offline).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
If I were just getting started I would agree. This import process app has been around a bit and does some manipulation along the way. It would be a real PITA to change direction now.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
con.Open()
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Eleve values('" + TextBox5.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + ComboBox1.Text + "','" + ComboBox2.Text + "','" + v + "','" + et + "','" + ComboBox5.Text + "','" + ComboBox6.Text + "')"
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
MessageBox.Show("l'enregistrement a reussi")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
ComboBox4.Text = ""
ComboBox5.Text = ""
ComboBox6.Text = ""
'Catch ex As Exception
'End Try
|
|
|
|
|
I think you forgot to ask a question.
|
|
|
|
|
Don't do it like that!
Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT
DROP TABLE MyTable; A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
Fix that throughout your app and your problem will likely go away at the same time.
But ... that code won't even compile - You've grabbed some VB code and dumped it into a C# app and just hoped like heck that adding a single semicolon will make it work. It won't: "'" is the VB comment marker, "//" is the C#, every line needs a semicolon to terminate it, and the VB was written by an idiot.
Always list the columns you want to INSERT into:
INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2) |If you don't, then SQL tries to insert them in the current table order, which means two things:
1) If the table order changes, your DB gets corrupted and that gets very difficult to fix quickly, but isn't generally spotted for a while - so by the time you get round to uncorrupting it, it's too badly mixed to be automatically fixed.
2) If you have an IDENTITY field for the Row ID, the INSERT will fail as SQL won;t let you write into it.
Even if it's currently "commented out", an empty catch block is nasty - it's a VB programmer way to not get error messages, so you don't realize that you've got a problem until it's too late. Always report or log errors so you can see what happened when teh problem become so noticeable that you have to fix them ...
Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: and the VB was written by an idiot.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: OriginalGriff wrote: and the VB was written by an idiot. I thought that was the default case.
|
|
|
|
|
That was a fantastic reply. Well done
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
How would you write a code where you asked to write a code using Luhn Algorithm
with the numbers 49927398716 using two methods .The first method will be called GenerateCheckDigit;A method to generate a checkdigit, and the other method is called ValidationNumber; A method to confirm whether a give number is valid by making use of Luhn algorithm
Please help me
Thank you in advance
|
|
|
|
|
I would start by researching the Luhn algorithm itself. There must be good resources online that describe the algorithm, possibly with pseudo-code. Once I had that, I would pull together an initial implementation; using known-good outputs to validate my implementation against.
What code do you currently have and where are you stuck?
|
|
|
|
|
Start by typing "Luhn Algorithm" into Google. This has been documented all over the web, with examples.
|
|
|
|
|
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Start with the related Wikipedia page[^], there is even the pseudocode implementation.
|
|
|
|
|
I wonder what your instructor would think knowing that you're asking other people to do your assignment
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I need to use a DataTable's column number in a switch statement.
I am having problems with the following:
const Int32 xxxColumn = (Int32)DataTable.xxxColumn.Ordinal;
switch (n)
{
case xxxColumn: ********; break;
}
How do I get a constant value from a DataTable column ordinal.
Any help will be appreciated,
Thanks in advance,
Michael
|
|
|
|
|
The parameter in a switch statement must be an actual constant whose value is available at compile time. Your code is using a variable that is not available to the compiler. You will need to use an if statement.
|
|
|
|
|
See if this gives you useful ideas:
public class SwitchOnDTOrdinal
{
public SwitchOnDTOrdinal(DataTable table)
{
TheTable = table;
validColumnNames = table.Columns
.Cast<DataColumn>()
.Select(col => col.ColumnName)
.ToList();
}
private List<string> validColumnNames;
private DataTable TheTable;
public void SwitchA(string cname)
{
if (! validColumnNames.Contains(cname))
{
throw new ArgumentException(@"{cname} is not a valid column name");
}
switch(TheTable.Columns[cname].Ordinal)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 1-Oct-19 6:48am.
|
|
|
|
|
Hi,
for Ordinal I agree with what has already been said. However you might consider working with the columns Name or Caption property; if one of those has known values you can still use a simple switch, as C# allows switching on string literals.
|
|
|
|
|
Dear all,
In my computer, there are have a software that used to encryte excel file.
All of these excel files can only read on computers that have this encryption / decryption program
I will make an C# system to load these excel files to datagridview.
Look forward to the help of all
Thanks all!
|
|
|
|
|
HoaiNTT0610 wrote: Look forward to the help of all To do what exactly?
|
|
|
|
|
At time of posting, there are 14,311,184 members at CP. Do you really want all of them to help?
Seriously though, you need to elaborate what help you are looking for.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
There is nowhere near enough information here for us to begin to help you - we have no idea what this " software that used to encryte excel file" is, what encryption method(s) it uses, how you use it, or how you propose to use it.
We don't even have any idea where you are stuck, or what help you might need - and that's kinda important, don't you think?
Start here: Asking questions is a skill[^] and think about what you need to know, and what you need to tell us in order to get help.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In Subclassing the edit control wparam in wm_nccalcsize return 1 only not 0 , and give me rgrc0 or rgrc1 bottom or right Zero so cannot decrease right of non client area and draw edge , before subclassing the Edit Control i used swp_framechanged in SetWindowpos to draw new style
|
|
|
|
|
You already posted this in the C/C++/MFC forum. Please do not repost.
|
|
|
|
|
This doesn't appear to have anything to do with C#.
|
|
|
|