question

KwebenaAcquah-9104 avatar image
0 Votes"
KwebenaAcquah-9104 asked ·

how to insert into specific column in a new multi column table in sql table

how can i do this

sqlcommand cmd= new sqlcommand("INSERT INTO tbl_A (columnA, columnB,
columnC)VALUES (@columnA, @columnB, @columnC)",conn);
cmd.parameter.Addwithvalue ("@columnA", textboxA);
cmd.parameter.ADdwithvalue("@columnB", textboxB);
cmd.ExecuteNonQuery();

is it possible to insert only on two columns when i have more than two columns in my sql table please can some one help me to achieve this.

i tried this code below:

 SqlConnection Conn = new SqlConnection(shoolmanangmentconn);
                             Conn.Open();
                             SqlCommand cmd = new SqlCommand("INSERT INTO tbl_TestingThatSubjects(INDO, LANGUAGE,BIOLOGY, GEOGRAPHY) VALUES (@IDNO,@LANGUAGE,@BIOLOGY,@GEOGRAPHY)", Conn);
                             cmd.Parameters.AddWithValue("@IDNO", txtids.Text); 
                             cmd.Parameters.AddWithValue("@LANGUAGE", txtlanguage.Text);
                             cmd.ExecuteNonQuery();


i am trying to insert into only at column LANGUAGE without inserting into other columns
please can someone teach me how to do the right thing. (am using wpf c#)

dotnet-csharpwindows-wpf
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KwebenaAcquah-9104
You could update your SqlCommand cmd = new SqlCommand("INSERT INTO tbl_TestingThatSubjects(INDO, LANGUAGE,BIOLOGY, GEOGRAPHY) VALUES (@IDNO,@LANGUAGE,@BIOLOGY,@GEOGRAPHY)", Conn); to SqlCommand cmd = new SqlCommand("INSERT INTO tbl_TestingThatSubjects(INDO, LANGUAGE) VALUES (@IDNO,@LANGUAGE)", Conn); , then you can insert IDNO and LANGUAGE without others.

0 Votes 0 ·

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered ·

If the row already exists, then use UPDATE:

 . . .
 SqlCommand cmd = new SqlCommand("UPDATE tbl_TestingThatSubjects SET [LANGUAGE] = @LANGUAGE WHERE IDNO = @IDNO", 
 Conn);
 . . .

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.