نوشته شده توسط
ژیار رحیمی
شما باید در فرم لود TextBox ها رو به فرم اضافه کنی بوسیله حلقه for که نمونه آبجکت های ان اضافه شود .الان این خطا مربوط به null بودن object های درون آرایه (تکست باکس ها)هست .
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
TextBox[] textBoxsArray=new TextBox[10];
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < textBoxsArray.Length; i++)
{
textBoxsArray[i] = new TextBox();
textBoxsArray[i].Location = new Point(210, i * 25);
this.Controls.Add(textBoxsArray[i]);
}
}
private void button1_Click(object sender, EventArgs e)
{
String q2 = "UPDATE " + s + " Set " + a + "='" + textBoxsArray[1].Text + "' where Name='" + btn + "';";
}
}
شما لطف کنید کد رو بررسی بفرمایید
public partial class Form13 : Form
{
public Form13()
{
InitializeComponent();
}
SQLiteConnection con = new SQLiteConnection("Data Source=TehranRED.JM;Version=3;");
string q1, s, btn,a;
TextBox[] text1 = new TextBox[68];
String[] t = new string[68];
public void check(String q1, String A, string B, string C, string D)
{
SQLiteCommand cmd1 = new SQLiteCommand(q1, con);
con.Open();
SQLiteDataReader reader = cmd1.ExecuteReader();
int i = 0;
while (reader.Read())
{
Label text = new Label();
text.Text = reader["name"].ToString();
text.Location = new Point(10, reader.StepCount * 25);
// tabControl1.Controls.Add(text);
this.Controls.Add(text);
text1 = new TextBox[reader.StepCount];
if (A != "")
{
text1[i] = new TextBox();
text1[i].Text = reader[A].ToString();
a = A;
text1[i].Location = new Point(110, reader.StepCount * 25);
this.Controls.Add(text1[i]);
}
i++;
Button button = new Button();
button.Text = s;
button.Location = new Point(550, reader.StepCount * 25);
button.Click += new EventHandler(button_click);
this.Controls.Add(button);
con.Close();
}
void button_click(object sender, EventArgs e)
{
String q3 = "select name from "+s;
SQLiteCommand cmd1 = new SQLiteCommand(q3, con);
con.Open();
SQLiteDataReader reader = cmd1.ExecuteReader();
int c = 0;
while (reader.Read())
{
if (c == 67)
{
break;
}
btn = reader["name"].ToString();
String q2 = "UPDATE " + s + " Set " + a + "="+ t[c] +" where Name='"+btn+"';";
SQLiteCommand cmd2 = new SQLiteCommand(q2, con);
SQLiteDataReader reader2 = cmd2.ExecuteReader();
C++;
}
con.Close();
MessageBox.Show("ok");
this.Controls.Clear();
this.Controls.Add(comboBox1);
this.Controls.Add(button1);
}
با تشکر