Click here to Skip to main content
15,899,475 members
Home / Discussions / C#
   

C#

 
GeneralRe: Auto submit using webbrowser component Pin
Dave_Roach15-Jul-06 13:47
Dave_Roach15-Jul-06 13:47 
AnswerRe: Auto submit using webbrowser component Pin
led mike15-Jul-06 11:47
led mike15-Jul-06 11:47 
GeneralRe: Auto submit using webbrowser component Pin
Dave_Roach15-Jul-06 13:44
Dave_Roach15-Jul-06 13:44 
GeneralRe: Auto submit using webbrowser component Pin
led mike15-Jul-06 15:57
led mike15-Jul-06 15:57 
QuestionResize quastion (Spliter) Pin
ytubis15-Jul-06 0:14
ytubis15-Jul-06 0:14 
AnswerRe: Resize quastion (Spliter) Pin
Andrew Lygin15-Jul-06 1:23
Andrew Lygin15-Jul-06 1:23 
Questiongetting inserted twice in SQL Table Pin
airandclouds14-Jul-06 23:54
airandclouds14-Jul-06 23:54 
AnswerRe: getting inserted twice in SQL Table [modified] Pin
Colin Angus Mackay15-Jul-06 5:35
Colin Angus Mackay15-Jul-06 5:35 
Have you ever thought about creating a DAL (Data Abstraction Layer) to put all your database access in? It would make your code much tidier.

This is the offending code:
SqlConnection cn=new SqlConnection("Persist Security Info=False;User ID=sa;Initial Catalog=CMS");
SqlCommand cm=new SqlCommand("insert into tblarticle
(articlename,athrid,articletext,articlekeywords,articlesummary) values
('"+this.txtarticlename.Text+"','"+Request.QueryString["aid"]
+"','"+this.txtarticletext.Text+"','"+this.txtkeywords.Text+"','"+this.txtsummary.Text+"');select 
@@identity as id;",cn);
cn.Open();
cm.ExecuteScalar();
cn.Close();
SqlDataAdapter da=new SqlDataAdapter(cm);
DataSet ds = new DataSet();
da.Fill(ds,"id");


First. It is suseptable to a SQL Injection Attack - You can find out what that is, how to recognise susceptable code and how to fix it here[^]

Second, the reason you are getting the row inserted twice is because you are asking it to get inserted twice.

This line inserts it the first time:
cm.ExecuteScalar();
And this line inserts it the second time:
da.Fill(ds,"id");
Why you are doing this I have no idea. It looks like you are trying to get the ID back out, but in doing so you are inserting the row twice.
The following should be sufficient:
int articleId = (int)cm.ExecuteScalar()

The remainder of the highlighted code after the cm.Close() can be removed.

Also, it looks like you are using a mix of styles, later in the code you are using a stored procedure. These conflicting styles will make code maintenance much more difficult in future. You should make a descicion to go all for stored srocedures (which is the option I recommend) or just don't use them at all.


Scottish Developers events:
* .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy
* Developer Day Scotland: are you interested in speaking or attending?

My: Website | Blog

-- modified at 11:36 Saturday 15th July, 2006
QuestionRead/Update flat files Pin
Krrish14-Jul-06 23:46
Krrish14-Jul-06 23:46 
AnswerRe: Read/Update flat files Pin
led mike15-Jul-06 16:18
led mike15-Jul-06 16:18 
GeneralRe: Read/Update flat files Pin
Krrish16-Jul-06 19:03
Krrish16-Jul-06 19:03 
GeneralRe: Read/Update flat files Pin
led mike16-Jul-06 19:47
led mike16-Jul-06 19:47 
GeneralRe: Read/Update flat files Pin
Krrish16-Jul-06 20:13
Krrish16-Jul-06 20:13 
QuestionIt must be >= 0 and < the PageCount Pin
vjain2314-Jul-06 19:23
vjain2314-Jul-06 19:23 
AnswerRe: It must be >= 0 and < the PageCount Pin
Colin Angus Mackay14-Jul-06 21:56
Colin Angus Mackay14-Jul-06 21:56 
AnswerRe: It must be >= 0 and < the PageCount Pin
Paul Conrad15-Jul-06 10:54
professionalPaul Conrad15-Jul-06 10:54 
QuestionRead location in .lnk (shortcut) file Pin
StyrofoamSUV14-Jul-06 18:56
StyrofoamSUV14-Jul-06 18:56 
AnswerRe: Read location in .lnk (shortcut) file Pin
kasik15-Jul-06 5:15
kasik15-Jul-06 5:15 
GeneralRe: Read location in .lnk (shortcut) file Pin
StyrofoamSUV15-Jul-06 6:46
StyrofoamSUV15-Jul-06 6:46 
QuestionHow can I display a .mht file on a webBrwoser control? Pin
AngryC14-Jul-06 15:49
AngryC14-Jul-06 15:49 
AnswerRe: How can I display a .mht file on a webBrwoser control? Pin
Andrew Lygin14-Jul-06 19:20
Andrew Lygin14-Jul-06 19:20 
QuestionStringCollection Property Design Time Editing Pin
Loophole14-Jul-06 13:10
Loophole14-Jul-06 13:10 
AnswerRe: StringCollection Property Design Time Editing Pin
Robert Rohde15-Jul-06 11:13
Robert Rohde15-Jul-06 11:13 
GeneralRe: StringCollection Property Design Time Editing Pin
Loophole17-Jul-06 6:12
Loophole17-Jul-06 6:12 
GeneralRe: StringCollection Property Design Time Editing Pin
Robert Rohde17-Jul-06 7:14
Robert Rohde17-Jul-06 7:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.