Click here to Skip to main content
15,908,661 members
Home / Discussions / C#
   

C#

 
AnswerRe: Auto submit using webbrowser component Pin
User 171649215-Jul-06 2:47
professionalUser 171649215-Jul-06 2:47 
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 
Problem:
I want to insert into article table a new article. later insert articleid (Autoincrement) and category selected from checkboxlist (can be more than one category) into another table articlecategory.

Now i used a 'for' loop to iterate to insert into table articlecategory.\

now the problem is the table article is getting inserted twice with the first insert.

PLease enlighten me.


the code in C#:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


namespace cmside
{
///
/// Summary description for article.
///

public class article : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnarticlesubmit;
protected System.Web.UI.WebControls.TextBox txtarticlename;
protected System.Web.UI.WebControls.TextBox txtarticletext;
protected System.Web.UI.WebControls.TextBox txtkeywords;
protected System.Web.UI.WebControls.TextBox txtsummary;
protected System.Web.UI.WebControls.CheckBoxList categorybox;


private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack==true)
{
SqlDataReader dr1;
SqlConnection con = new SqlConnection("Persist Security Info=False;User ID=sa;Initial Catalog=CMS");
SqlCommand cmd = new SqlCommand("select categoryID,categoryName from tblcategory",con);

con.Open();
dr1 = cmd.ExecuteReader();

this.categorybox.DataSource=dr1;
this.categorybox.DataTextField="categoryName";
this.categorybox.DataValueField="categoryID";
this.categorybox.DataBind();

dr1.Close();
con.Close();
}


}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.btnarticlesubmit.Click += new System.EventHandler(this.btnarticlesubmit_Click);

this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnarticlesubmit_Click(object sender, System.EventArgs e)
{
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");

int j = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
cn.Dispose();
cm.Dispose();


SqlConnection cn1=new SqlConnection("Persist Security Info=False;User ID=sa;Initial Catalog=CMS");
SqlCommand cmins= new SqlCommand("insertintoarticletocat",cn1);

cmins.CommandType=CommandType.StoredProcedure;
SqlParameter myparam = cmins.Parameters.Add("@categoryID",SqlDbType.Int);

SqlParameter myparam1 = cmins.Parameters.Add("@articleID",SqlDbType.Int);


for(int i = 0;i
AnswerRe: getting inserted twice in SQL Table [modified] Pin
Colin Angus Mackay15-Jul-06 5:35
Colin Angus Mackay15-Jul-06 5:35 
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 

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.