2016-04-01 12 views
0

Şu anda görsel stüdyo 2015 ve SQL sunucusunda bir iş topluluğu için küçük bir proje üzerinde çalışıyorum. İki hesap kutum var "AccountCode" ve "AccountNo". "AccountCode" açılır listesinden bir metnin seçilmesiyle yazışmadaki değerini değiştirmek için "AccountNo" açılan kutusunu yapmak istiyorum. Ama aşağıdaki hatayı alıyorum:combobox açılır menüsü nasıl açılır listesini başka bir combobox'a göre değiştirir?

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: The multi-part identifier "System.Data.DataRowView" could not be bound.

private void cmBxAccountCode_DataEntry_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     cmBxAccountNo_DataEntry.ResetText(); 
     cmBxAccountNo_DataEntry.Refresh(); 
     DataSet ds = new DataSet(); 
     da.SelectCommand = new SqlCommand("SELECT ID,ACCOUNTNO FROM AccountHolder WHERE ACCOUNTCODE =" + cmBxAccountCode_DataEntry.Text, SQLConnection.con); 
     da.Fill(ds); 
     cmBxAccountNo_DataEntry.DataSource = ds.Tables[0]; 
     cmBxAccountNo_DataEntry.DisplayMember = "ACCOUNTNO"; 
     cmBxAccountNo_DataEntry.ValueMember = "ID"; 
    } 

cevap

0

Sorgunuz böyle olmalı:

SELECT ID,ACCOUNTNO FROM AccountHolder WHERE ACCOUNTCODE ='" + cmBxAccountCode_DataEntry.Text + "'" 

Ama şiddetle enjeksiyon önlemek için Parametreli sorgular kullanmayı tavsiye; Ve ayrıca Text için seçilen değeri al (ancak veritabanındaki değere göre). parametreli sorgu şu şekilde olacaktır: BM-şanslı @

// Code here 
SqlCommand selectCommand= new SqlCommand("SELECT ID,ACCOUNTNO FROM AccountHolder WHERE ACCOUNTCODE [email protected]", SQLConnection.con); 
selectCommand.Parameters.Add("@accountCode", SqlDbType.VarChar).Value = cmBxAccountCode_DataEntry.Text; 
// execute here 
+0

teşekkürler. Anladım ve problemim çözüldü! :) –

İlgili konular