Click here to Skip to main content
12,632,698 members (32,876 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# SQL-Server C#4.0
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 2:18am
Updated 20-Apr-12 2:20am
sravani.v15.9K
v3
Comments
Prasad Kulkarni (pashad) 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?
Member 8845505 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 20-Apr-12 7:29am
   
5!
Member 8845505 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.
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 20 Apr 2012
Copyright © CodeProject, 1999-2016
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