Click here to Skip to main content
15,923,083 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to export data to sql uploaded in web Pin
Paul Conrad15-Jan-14 5:39
professionalPaul Conrad15-Jan-14 5:39 
GeneralRe: how to export data to sql uploaded in web Pin
Pete O'Hanlon15-Jan-14 5:42
mvePete O'Hanlon15-Jan-14 5:42 
GeneralRe: how to export data to sql uploaded in web Pin
Paul Conrad15-Jan-14 5:50
professionalPaul Conrad15-Jan-14 5:50 
GeneralRe: how to export data to sql uploaded in web Pin
Paul Conrad15-Jan-14 5:38
professionalPaul Conrad15-Jan-14 5:38 
GeneralRe: how to export data to sql uploaded in web Pin
fatemehsoleimani16-Jan-14 4:26
fatemehsoleimani16-Jan-14 4:26 
AnswerRe: how to export data to sql uploaded in web Pin
Prabhu S M15-Jan-14 0:48
Prabhu S M15-Jan-14 0:48 
QuestionMySQL connection [solved] Pin
V.13-Jan-14 2:36
professionalV.13-Jan-14 2:36 
AnswerRe: MySQL connection [solved] Pin
OriginalGriff13-Jan-14 6:21
mveOriginalGriff13-Jan-14 6:21 
Questionnetwork printer management Pin
iraheb12-Jan-14 0:25
iraheb12-Jan-14 0:25 
AnswerRe: network printer management Pin
OriginalGriff12-Jan-14 1:47
mveOriginalGriff12-Jan-14 1:47 
AnswerRe: network printer management Pin
Marco Bertschi12-Jan-14 5:14
protectorMarco Bertschi12-Jan-14 5:14 
Questionimport dat from excel to sql Pin
fatemehsoleimani10-Jan-14 23:24
fatemehsoleimani10-Jan-14 23:24 
AnswerRe: import dat from excel to sql Pin
Richard MacCutchan10-Jan-14 23:56
mveRichard MacCutchan10-Jan-14 23:56 
GeneralRe: import dat from excel to sql Pin
fatemehsoleimani11-Jan-14 7:31
fatemehsoleimani11-Jan-14 7:31 
Questionhow to display the value of id result in access database in a datagridview using c# Pin
Member 1049158710-Jan-14 6:02
Member 1049158710-Jan-14 6:02 
AnswerRe: how to display the value of id result in access database in a datagridview using c# Pin
Eddy Vluggen10-Jan-14 6:21
professionalEddy Vluggen10-Jan-14 6:21 
QuestionSQL Primary Key Issue Pin
Glen Childs10-Jan-14 0:21
Glen Childs10-Jan-14 0:21 
AnswerRe: SQL Primary Key Issue Pin
Wayne Gaylard10-Jan-14 0:50
professionalWayne Gaylard10-Jan-14 0:50 
AnswerRe: SQL Primary Key Issue Pin
Simon_Whale10-Jan-14 1:35
Simon_Whale10-Jan-14 1:35 
QuestionHow can I get HotSpot and Size of mouse cursor in C#? Pin
job@3deden.com9-Jan-14 21:27
job@3deden.com9-Jan-14 21:27 
AnswerRe: How can I get HotSpot and Size of mouse cursor in C#? Pin
Richard MacCutchan9-Jan-14 22:54
mveRichard MacCutchan9-Jan-14 22:54 
QuestionHOw can i export multiple datagridview to an excel file with multiple sheet Pin
Real_Criffer9-Jan-14 2:45
Real_Criffer9-Jan-14 2:45 
AnswerRe: HOw can i export multiple datagridview to an excel file with multiple sheet Pin
237419-Jan-14 3:03
237419-Jan-14 3:03 
AnswerRe: HOw can i export multiple datagridview to an excel file with multiple sheet Pin
Eddy Vluggen9-Jan-14 8:53
professionalEddy Vluggen9-Jan-14 8:53 
QuestionVisual Studio 2010 - Set IDENTITY_INSERT <Table> ON Pin
Member 105135979-Jan-14 2:03
Member 105135979-Jan-14 2:03 
Hello!

I was having some trouble with this error, but i added the command, and now i receive another error. Please, check out my code:

C#
protected void btnAdd_Client(object sender, System.EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=JOHN-PC\SQLEXPRESS;Initial Catalog=subiect1;Integrated Security=True");
            try
            {
                con.Open();
                SqlCommand command = new SqlCommand("SET IDENTITY_INSERT Clienti ON");
                command.ExecuteNonQuery();
                SqlCommand cmd = new SqlCommand("insert into Clienti(ID, Nume, Prenume, Data_Nasterii, Adresa_mail) values(@ID, <a href="/Members/nume">@Nume</a> @Prenume, @Data_Nasterii, @Adresa_mail)", con);
                cmd.Parameters.AddWithValue("@ID", txtID.Text);
                cmd.Parameters.AddWithValue("@Nume", txtNume.Text);
                cmd.Parameters.AddWithValue("@Prenume", txtPrenume.Text);
                cmd.Parameters.AddWithValue("@Data_Nasterii", txtDataNastere.Text);
                cmd.Parameters.AddWithValue("@Adresa_mail", txtAdresamail.Text);

                int count = cmd.ExecuteNonQuery();
                if (count == 1)
                    lblMsg.Text = "Clientul [" + txtID.Text + "] a fost adaugat!";
                else
                    lblMsg.Text = "Clientul nu a putut fi adaugat!";
            }
            catch (Exception ex)
            {
                lblMsg.Text = "Error --> " + ex.Message;
            }
            finally
            {
                SqlCommand command = new SqlCommand("SET IDENTITY_INSERT Clienti OFF");
                command.ExecuteNonQuery();
                con.Close();
            }
        }


This is a function which adds new clients in my local database. As you can see, i placed the set_identity commands before and after the actual adding client code. What do i miss here?

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.