Click here to Skip to main content
11,505,166 members (68,834 online)
Rate this: bad
good
Please Sign up or sign in to vote.
Hi Guy i need Ur Help,
what i do wrong??
Here hier is my code

SqlConnection connection = new SqlConnection("Data Source= .\\SQLEXPRESS;"+
            " Initial Catalog= zeit; integrated security = true");
 

SqlDataAdapter data = new SqlDataAdapter();
 
data.InsertCommand = new SqlCommand("insert into AbhängigkeitTabelle"+
    "values("+
     "Select V_ID from Netzplan where V_Name = '@VName')"+
    ",(select Vorgang_ID from Netzplan_2 where Abhängigkeiten ='@Ab' ))", connection);
data.InsertCommand.Parameters.Add("@VName", SqlDbType.VarChar).Value = VorgangNameTextBox.Text;
data.InsertCommand.Parameters.Add("@Ab", SqlDbType.VarChar).Value = AbhängigkeitenTextBox.Text;
 

connection.Open();
data.InsertCommand.ExecuteNonQuery();
MessageBox.Show(" Datei eingefügt");
connection.Close();


I Think something is wrong with my new SqlCommand but i don't know why.
Posted 20-Apr-12 1:18am
Edited 20-Apr-12 1:20am
sravani.v15.8K
v3
Comments
Prasad Kulkarni (pashad) at 20-Apr-12 7:20am
   
Do you getting any error?? What exact problem is?? Please clarify
bhagirathimfs at 20-Apr-12 7:21am
   
what is the error message?
Member 8845505 at 20-Apr-12 7:44am
   
Firstly i see that i forget to put a space between values and my table. after that i put the space i receve this error

Incorrect syntax near the keyword 'Select'.
Incorrect syntax near ')'.
Incorrect syntax near ')'.

how can i resolv it??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi

I think
Select V_ID from Netzplan where V_Name = '@VName'
select Vorgang_ID from Netzplan_2 where Abhängigkeiten ='@Ab'
the above query is returning more than one row.

please check the above query should not return more than one row in every case.
means:V_Name and Abhängigkeiten columns must be unique type.
  Permalink  
v2
Comments
sravani.v at 20-Apr-12 7:29am
   
5!
Member 8845505 at 20-Apr-12 7:30am
   
and how can i repare it please. in SQL Server all is Ok but how can i do so that it walk in c# please?
bhagirathimfs at 20-Apr-12 7:41am
   
In the where clause use unique value stored column.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi there,

I caught your error..

Try this.

SqlConnection connection = new SqlConnection("Data Source= .\\SQLEXPRESS;"+
            " Initial Catalog= zeit; integrated security = true");
 
 
SqlDataAdapter data = new SqlDataAdapter();
 
data.InsertCommand = new SqlCommand("insert into AbhängigkeitTabelle"+
    " values("+
     "Select V_ID from Netzplan where V_Name = '@VName')"+
    ",(select Vorgang_ID from Netzplan_2 where Abhängigkeiten ='@Ab' )", connection);
data.InsertCommand.Parameters.Add("@VName", SqlDbType.VarChar).Value = VorgangNameTextBox.Text;
data.InsertCommand.Parameters.Add("@Ab", SqlDbType.VarChar).Value = AbhängigkeitenTextBox.Text;
 
 
connection.Open();
data.InsertCommand.ExecuteNonQuery();
MessageBox.Show(" Datei eingefügt");
connection.Close();

This may help you.. All the best.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 477
1 F-ES Sitecore 380
2 Richard Deeming 270
3 CHill60 195
4 Richard MacCutchan 190
0 Sergey Alexandrovich Kryukov 723
1 Peter Leow 490
2 Maciej Los 475
3 DamithSL 470
4 OriginalGriff 437


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 20 Apr 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100