Jump to content
Son zamanlarda artan kullanıcı hesap hırsızlıkları sebebiyle tüm kullanıcılara şifre sıfırlama maili gönderilmiştir. Lütfen güveli şifreler seçiniz. Mevcut e-mail adresinize erişemiyorsanız, en aşağıdaki destek linkinden bize ulaşınız. ×

C# Sql Bağlantısında Problem


CaNCaN
 Share

Recommended Posts

[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 by CaNCaN
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by CaNCaN
Link to comment
Share on other sites

"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 by Scarecrow
Link to comment
Share on other sites

[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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

Allah allah ya nerde bu hata :wacko:
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 by Scarecrow
Link to comment
Share on other sites

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 by CaNCaN
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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 by CaNCaN
Link to comment
Share on other sites

[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 by CaNCaN
Link to comment
Share on other sites

[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. :wacko:

Link to comment
Share on other sites

[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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

[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 by CaNCaN
Link to comment
Share on other sites

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)
{

Link to comment
Share on other sites

[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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...