PDA

View Full Version : مشکل با درج اطلاعات در فیلد



mohammad2407
شنبه 21 بهمن 1391, 16:29 عصر
دوستان من از کد زیر استفاده میکنم برای درج ولی متاسفانه از خط های 41 و 42 ایراد میگیره

میشه راهنمایی کنید


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 record2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool newMode;
DataSet ds = new DataSet();
string sql = null;
string constr = "Data Source=.;Initial Catalog=iran;Integrated Security=True";

SqlDataAdapter da = null;
SqlConnection con = null;
DataRow newrow = null;
SqlCommandBuilder cb = null;

private void fillds()
{
con = new SqlConnection(constr);
if (con.State == ConnectionState.Open)
con.Close();
sql = "select * from Ostan";
con.Open();
da = new SqlDataAdapter(sql, con);
ds.Clear();
da.Fill(ds, "name");
textBox1.DataBindings.Clear();
textBox2.DataBindings.Clear();
textBox1.DataBindings.Add(new Binding("text", ds, "Ostan.OstanCode"));
textBox2.DataBindings.Add(new Binding("text", ds, "Ostan.OstanName"));
con.Close();
}
private void cleartextbox()
{
textBox1.Text = "";
textBox2.Text = "";
}
private void displayposition()
{
textRecord.Text = Convert.ToString(this.BindingContext[ds, "Ostan"].Position + 1);
textRecord.Text += "از" + Convert.ToString(this.BindingContext[ds, "Ostan"].Count);
}

private void Form1_Load(object sender, EventArgs e)
{
label1.Text = "کد استان";
label2.Text = "نام استان";
newMode = false;
this.RightToLeft = RightToLeft.Yes;
this.Text = "کار با جدول";
textRecord.TextAlign = HorizontalAlignment.Center;
fillds();
displayposition();

}

private void اضافهToolStripMenuItem_Click(object sender, EventArgs e)
{
newrow = ds.Tables["Ostan"].NewRow();
newMode = true;
MessageBox.Show("رکورد را وارد کرده گزینه ");
textRecord.Text = "در حال درج رکورد";
cleartextbox();
}
}
}

naghshineh m&h
شنبه 21 بهمن 1391, 20:22 عصر
دوست عزیز دو خط اشتباه نوشتی نوع بایند کردن ایراد داره به مثال زیر توجه کن برای یک نرم افزار خودم هست

objDataAdapter = new SqlDataAdapter("SELECT Top 1 shomarehCheshmpezeshki FROM Cheshmpezeshki WHERE namepezeshkCheshmpezeshki=@namepezeshk ORDER BY CheshPezeshki_ID DESC ", ObjSqlConnection);
objDataAdapter.SelectCommand.Parameters.AddWithVal ue("@namepezeshk", cmboxNamePezeshk.Text);
objDataSet = new DataSet();
// Fill the DataSet object with data...
objDataAdapter.Fill(objDataSet, "Cheshmpezeshki");
// Set the DataView object to the DataSet object...
objDataView = new DataView(
objDataSet.Tables["Cheshmpezeshki"]);

txtVisitNumber.DataBindings.Add("TEXT", objDataView, "shomarehCheshmpezeshki");



objDataAdapterID = new SqlDataAdapter("SELECT TOP 1 CheshPezeshki_ID FROM Cheshmpezeshki ORDER BY CheshPezeshki_ID DESC", ObjSqlConnection);
objDataSetID = new DataSet();
objDataAdapterID.Fill(objDataSetID, "Cheshmpezeshki");
objDataViewID = new DataView(
objDataSetID.Tables["Cheshmpezeshki"]);

txtCheshmPezeshki_ID.DataBindings.Add("TEXT", objDataViewID, "CheshPezeshki_ID");