با سلام
بنده یه برنامه نوشتم اطلاعات در هنگام ثبت به صورت کاملا صحیح در جدول SQl ذخیره شده و نمایش آن هم صحیح است اما وقتی می خواهیم اطلاعات رو ویرایش کنیم مقادیر به صورت علامت سوال در SQL ذخیره می شوند و به صورت علامت سوال ؟ نیز نمایش می دهد
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;
using System.Data.SqlClient;
namespace projecta
{
public partial class form_tanzimat : Form
{
public form_tanzimat()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection("Data source=(local); initial catalog=Anbardariidb; integrated security=true");
SqlCommand cmd = new SqlCommand();
void Display()
{
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = new SqlCommand();
adp.SelectCommand.Connection = con;
adp.SelectCommand.CommandText = "select * from tanzimat";
adp.Fill(ds, "tanzimat");
dgvtanzimat.DataSource = ds;
dgvtanzimat.DataMember = "tanzimat";
}
private void form_tanzimat_Load(object sender, EventArgs e)
{
Display();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void groupPanel2_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void btnsave_Click(object sender, EventArgs e)
{
cmd.Connection = con;
cmd.Parameters.Clear();
cmd.CommandText = "insert into tanzimat (tel,mobile,address,Tozih)values(@b,@c,@d,@e)";
cmd.Parameters.AddWithValue("@b", txtTel.Text);
cmd.Parameters.AddWithValue("@c", txtmobile.Text);
cmd.Parameters.AddWithValue("@d", txtaddress.Text);
cmd.Parameters.AddWithValue("@e", txtTozih.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show(" ثبت با موفقیت انجام شد ");
Display();
}
private void txtId_TextChanged(object sender, EventArgs e)
{
}
private void dgvtanzimat_MouseUp(object sender, MouseEventArgs e)
{
txtId.Text = dgvtanzimat[0, dgvtanzimat.CurrentRow.Index].Value.ToString();
txtTel.Text = dgvtanzimat[1, dgvtanzimat.CurrentRow.Index].Value.ToString();
txtmobile.Text = dgvtanzimat[2, dgvtanzimat.CurrentRow.Index].Value.ToString();
txtaddress.Text = dgvtanzimat[3, dgvtanzimat.CurrentRow.Index].Value.ToString();
txtTozih.Text = dgvtanzimat[4, dgvtanzimat.CurrentRow.Index].Value.ToString();
}
private void btndelet_Click(object sender, EventArgs e)
{
cmd.Parameters.Clear();
cmd.Connection = con;
cmd.CommandText = "delete from tanzimat where IdTanzimat=@N";
cmd.Parameters.AddWithValue("@N", txtId.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("حذف با موفقیت انجام شد");
Display();
}
private void btnEdit_Click(object sender, EventArgs e)
{
cmd.Connection = con;
cmd.Parameters.Clear();
cmd.CommandText = "update tanzimat set Tel='" + txtTel.Text + "',mobile='" + txtmobile.Text + "',Address='" + txtaddress.Text + "',Tozih='" + txtTozih.Text + "' where IdTanzimat= " + txtId.Text;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("ویرایش با موفقیت انجام شد");
Display();
}
}
}