Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Guy i need Ur Help,
what i do wrong??
Here hier is my code

SQL
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
Updated 20-Apr-12 1:20am
v3
Comments
Prasad_Kulkarni 20-Apr-12 7:20am    
Do you getting any error?? What exact problem is?? Please clarify
bhagirathimfs 20-Apr-12 7:21am    
what is the error message?
stefan from germany 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??

Hi
I think
SQL
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.
 
Share this answer
 
v2
Comments
sravani.v 20-Apr-12 7:29am    
5!
stefan from germany 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 20-Apr-12 7:41am    
In the where clause use unique value stored column.
Hi there,

I caught your error..

Try this.

C#
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900