CaNCaN Posted April 15, 2011 Share Posted April 15, 2011 (edited) [code] SqlConnection bag = new SqlConnection(); bag.ConnectionString = @"Data Source=cancan-PC\SQLEXPRESS; Initial Catalog=Northwind; User Id=cancan; Password=123;) "; bag.Open(); String Malzeme_adi = textBox1.Text; String Malzeme_cinsi = textBox2.Text; String Malzeme_tutar = textBox3.Text; SqlCommand komut = new SqlCommand(); komut.CommandText = "insert into Malzeme (malzeme_adi,malzeme_cinsi,malzeme_tutar) values ('" +Malzeme_adi + "','" + Malzeme_cinsi + "','" + Malzeme_tutar +"')"; komut.Connection = bag; komut.ExecuteNonQuery(); bag.Close(); [/code] Problemim var aarkadaşlar SQl bağlantısında yardımcı olursanız sevinirim. aldığım hata:Format of the initialization string does not conform to specification starting at index 86. Edited April 15, 2011 by CaNCaN Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 hata devam ediyor. Quote Link to comment Share on other sites More sharing options...
alisky Posted April 15, 2011 Share Posted April 15, 2011 komut.CommandText = "insert into Malzeme (malzeme_adi,malzeme_cinsi,malzeme_tutar) values ('" +textbox1.txt + "','" + Malzeme_cinsi + "','" + Malzeme_tutar +"')"; şeklinde yapman lazım yani +Malzeme_adi + yerine +textbox1.text+ şeklinde Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 (edited) dediğin şekilde yaptım hala [u][b]Format of the initialization string does not conform to specification starting at index 86.[/u] bu hatayı alıyorum[/b] Edited April 15, 2011 by CaNCaN Quote Link to comment Share on other sites More sharing options...
Scarecrow Posted April 15, 2011 Share Posted April 15, 2011 (edited) "insert into Malzeme (malzeme_adi,malzeme_cinsi,malzeme_tutar) values ('" +Malzeme_adi + "','" + Malzeme_cinsi + "','" + Malzeme_tutar +"'[size="5"][color="#ff0000"]"[/color][/size])"; Kırmızı Renkli Tırnağı Ekle. Edited April 15, 2011 by Scarecrow Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 [quote name='Scarecrow' date='15 April 2011 - 18:37 ' timestamp='1302892645' post='993383'] "insert into Malzeme (malzeme_adi,malzeme_cinsi,malzeme_tutar) values ('" +Malzeme_adi + "','" + Malzeme_cinsi + "','" + Malzeme_tutar +"'[size="5"][color="#ff0000"]"[/color][/size])"; Kırmızı Renkli Tırnağı Ekle. [/quote] + Malzeme_tutar +"'")"; eklediğimde 7 hata veriyor, oradaki [color="#FF0000"][size="4"]"[/size][/color] fazla tırnak uyarısı veriyor ondan olduğunu tahmin etmiyorum abi Quote Link to comment Share on other sites More sharing options...
Scarecrow Posted April 15, 2011 Share Posted April 15, 2011 O zaman şöyle bi kod dene: [code]SqlCommand komut = new SqlCommand(); komut.CommandText = "insert into Malzeme (malzeme_adi,malzeme_cinsi,malzeme_tutar) values (@1,@2,@3)"; komut.Parameters.Clear(); komut.Parameters.AddWithValue("@1",textbox1.Text); komut.Parameters.AddWithValue("@2",textbox2.Text); komut.Parameters.AddWithValue("@3",textbox3.Text); komut.Connection = bag; komut.ExecuteNonQuery(); bag.Close();[/code] Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 [b]yaw bu hata delirtecek beni Format of the initialization string does not conform to specification starting at index 86 aynı hatayı alıyorum.[/b] Quote Link to comment Share on other sites More sharing options...
Scarecrow Posted April 15, 2011 Share Posted April 15, 2011 (edited) Allah allah ya nerde bu hata Edit : Galiba hata connectionstring inde bi daha gözden geçirsene Edit 2 : Buldum bag.ConnectionString = @"Data Source=cancan-PC\SQLEXPRESS; Initial Catalog=Northwind; User Id=cancan; Password=123[size="7"][color="#ff0000"];[/color][/size]) "; noktalı virgülü sil Edited April 15, 2011 by Scarecrow Quote Link to comment Share on other sites More sharing options...
Scarecrow Posted April 15, 2011 Share Posted April 15, 2011 Çözüldü mü sorun? Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 (edited) yemekteydim ustad; bag.ConnectionString = @"Data Source=cancan-PC\SQLEXPRESS; Initial Catalog=Northwind; User Id=cancan; Password=123;) "; pardon sil demişsin okumadım orayı dediğin şekilde ayarladım bu sfeer başka hata veriyor; ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. Edited April 15, 2011 by CaNCaN Quote Link to comment Share on other sites More sharing options...
Scarecrow Posted April 15, 2011 Share Posted April 15, 2011 sildin mi noktalı virgülü Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 evet noktalı virgülü sildim farklı bir hata alıyorum mesajda yazdım tekrar yazayım; [b]ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.[/b] Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 (edited) ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. bu hatayı bag.open(); açılmadığından veriyormuş ki ben açtım diyebiliyorum neyse onu ekledim code son hali bu; ancak farklı bir noktada tekrar hata alıyorum ustad. hatada bu; [code]A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - Borunun diğer ucunda işlem yok.)[/code] [code]SqlConnection bag = new SqlConnection(); bag.ConnectionString = @"Data Source=cancan-PC\SQLEXPRESS; Initial Catalog=Northwind; User Id=cancan; Password=123) "; String Malzeme_adi = textBox1.Text; String Malzeme_cinsi = textBox2.Text; String Malzeme_tutar = textBox3.Text; SqlCommand komut = new SqlCommand(); bag.Open(); komut.CommandText = "insert into Malzeme (malzeme_adi,malzeme_cinsi,malzeme_tutar) values (@1,@2,@3)"; komut.Parameters.Clear(); komut.Parameters.AddWithValue("@1", textBox1.Text); komut.Parameters.AddWithValue("@2", textBox2.Text); komut.Parameters.AddWithValue("@3", textBox3.Text); komut.Connection = bag; komut.ExecuteNonQuery(); bag.Close(); [/code] Edited April 15, 2011 by CaNCaN Quote Link to comment Share on other sites More sharing options...
sPYcas Posted April 15, 2011 Share Posted April 15, 2011 bag.ConnectionString = @"Data Source=MERT-PC\\SQLEXPRESS; Initial Catalog=Northwind; User Id=mert; Password=123) bu şekilde değiştir öle yap. tek şılaı farklı komut olarak alıgılar C# kolay gelsin... Quote Link to comment Share on other sites More sharing options...
Scarecrow Posted April 15, 2011 Share Posted April 15, 2011 Bugünlerde ben de sql ile uğraşıyorum SqlConnection ı elle yazmak yerine Toolbox tan SqlConnection ekleyip gerekli bağlantıları yapmanı tavsiye ederim. Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 (edited) [quote name='Scarecrow' date='15 April 2011 - 20:10 ' timestamp='1302898232' post='993451'] Bugünlerde ben de sql ile uğraşıyorum SqlConnection ı elle yazmak yerine Toolbox tan SqlConnection ekleyip gerekli bağlantıları yapmanı tavsiye ederim. [/quote] olur abim ,çözmeye çalışayım olmasa senin dediğn yöntem daha mantıklı haklısın,teşekkür ediyorum. Edited April 15, 2011 by CaNCaN Quote Link to comment Share on other sites More sharing options...
cumman Posted April 15, 2011 Share Posted April 15, 2011 komut.ExecuteNonQuery(); tan once bag.open(); satirini ekle Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 [quote name='sPYcas' date='15 April 2011 - 20:09 ' timestamp='1302898166' post='993450'] bag.ConnectionString = @"Data Source=MERT-PC\\SQLEXPRESS; Initial Catalog=Northwind; User Id=mert; Password=123) bu şekilde değiştir öle yap. tek şılaı farklı komut olarak alıgılar C# kolay gelsin... [/quote] [u][b]Instance failure.[/b][/u] hatası aldım bu sefer off. Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 [quote name='cumman' date='15 April 2011 - 20:22 ' timestamp='1302898961' post='993458'] komut.ExecuteNonQuery(); tan once bag.open(); satirini ekle [/quote] [u][b]Instance failure.[/b][/u] hatası aldım bu sefer off Quote Link to comment Share on other sites More sharing options...
sPYcas Posted April 15, 2011 Share Posted April 15, 2011 baglanti.ConnectionString = ("Data Source=LAB3-000\\LAB342; database=personel; trusted_connection=true; "); SqlDataAdapter adapter; adapter = new SqlDataAdapter("SELECT * FROM kisiler1", baglanti); DataSet verikumesi; verikumesi = new DataSet(); adapter.Fill(verikumesi, "kisiler1"); dataGridView1.DataSource = verikumesi.Tables["kisiler1"]; Örnek veritabanı baglantısı ve datagride listelenmesi... bu komutlar çalışyor kardeş.. tabi öncesinde programın başında using kısmında şu tanımlamayı yapman gerekir yaptın bilmiyorum... KOD: using System.Data.SqlClient; Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 (edited) [code]using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; [b][color="#FF0000"]using System.Data.SqlClient;[/color][/b] namespace WindowsFormsApplication13 { public partial class Malzeme : Form { public Malzeme() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { SqlConnection bag = new SqlConnection(); bag.ConnectionString = @"Data Source=MERT-PC\\SQLEXPRESS; Initial Catalog=Northwind; User Id=mert; Password=123) "; SqlCommand komut = new SqlCommand(); String Malzeme_adi = textBox1.Text; String Malzeme_cinsi = textBox2.Text; String Malzeme_tutar = textBox3.Text; bag.Open(); komut.CommandText = "insert into Malzeme (malzeme_adi,malzeme_cinsi,malzeme_tutar) values ('" + textBox1.Text + "','" + textBox2.Text+ "','" + textBox3.Text+ "')"; komut.Connection = bag; komut.ExecuteNonQuery(); bag.Close(); [/code] Edited April 15, 2011 by CaNCaN Quote Link to comment Share on other sites More sharing options...
sPYcas Posted April 15, 2011 Share Posted April 15, 2011 sql connectionu yanlış yerde tanımlamışın. Şu şekilde olacak.. KOD: using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace canana { public partial class Form1 : Form { public Form1() { InitializeComponent(); } SqlConnection baglanti = new SqlConnection(); private void button4_Click(object sender, EventArgs e) { Quote Link to comment Share on other sites More sharing options...
CaNCaN Posted April 15, 2011 Author Share Posted April 15, 2011 (edited) sorun aynı edit:Instance failure. hatası alıyorum Edited April 15, 2011 by CaNCaN Quote Link to comment Share on other sites More sharing options...
galetis Posted April 15, 2011 Share Posted April 15, 2011 [code] SqlConnection baglanti = new SqlConnection("Data Source=PC;Initial Catalog=db;Integrated Security=True"); baglanti.Open(); SqlCommand Baglan = new SqlCommand("insert into dbo.tablo (sutun1,sutun2) values ('" + deger1 + "','" + deger2 + "')", baglanti); Baglan.ExecuteNonQuery(); baglanti.Close(); [/code] Kardeş ben şablon olarak bu komutu kullanıyorum işlemlerimde. Pek bi fark göremedim ama bu kodları bi dene istersen. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.