PDA

View Full Version : مبتدی: رفع خطا در برقرای ارتباط با بانک اکسس



mahmoud_monfaredi
جمعه 02 آبان 1393, 12:11 عصر
سلام خدمت همه اساتید لطفا کمک کنید

قراره که یه سری کد تولید بشه و در بانک ذخیره بشه
لطفا کد رو بررسی کنید و رفع خطا کنید

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con1 = new SqlConnection("Data Source=.;Initial Catalog=serial;Integrated Security=True");










private void button4_Click(object sender, EventArgs e)


{
//************************************************** *******






//************************************************** *******
con1.Open();
SqlCommand com1 = new SqlCommand();
com1.Connection = con1;
com1.CommandType = CommandType.Text;
//////////////////////////////////////
char[] cod6 = new char[6];
char[] p = { '1', '0' };
char[] serial = new char[8];
char[] sumA = new char[2];
string s8;
//در مرحله اول 10000 سریال ایجاد می شود
for (Int32 n = 112233; n < 112233 + 10000; n++)
{
cod6 = n.ToString().ToCharArray();
serial[0] = p[0];
serial[1] = cod6[0];
serial[2] = cod6[1];
serial[3] = cod6[2];
serial[4] = cod6[3];
serial[5] = cod6[4];
serial[6] = cod6[5];
serial[7] = p[1];

s8 = serial[0].ToString() + serial[1].ToString() + serial[2].ToString() + serial[3].ToString() + serial[4].ToString() + serial[5].ToString() + serial[6].ToString() + serial[7].ToString();


com1.CommandText = "insert into serialha_site(cod8,cod2,idc)values('" + s8 + "',10,'0000')";
com1.ExecuteNonQuery();






}
con1.Close();
MessageBox.Show("end proccess");




}






/*
private void button9_Click(object sender, EventArgs e)
{

con1.Open();
SqlCommand com1 = new SqlCommand();
com1.Connection = con1;
com1.CommandType = CommandType.Text;
//////////////////////////////////////
char[] cod6 = new char[6];
char[] p = { '1', '2' }; /// شماره محصول را مشخص کنید
char[] serial = new char[10];
char[] sumA = new char[2];
string s10;
//در مرحله اول 10000 سریال ایجاد می شود
for (Int32 n = 112233; n < 112233 + 10000; n++)
{
cod6 = n.ToString().ToCharArray();
serial[0] = p[0];
serial[1] = cod6[0];
serial[2] = cod6[1];
serial[3] = cod6[2];
serial[4] = cod6[3];
serial[5] = cod6[4];
serial[6] = cod6[5];
serial[7] = p[1];
int sum = int.Parse(serial[0].ToString()) + int.Parse(serial[1].ToString()) + int.Parse(serial[2].ToString()) + int.Parse(serial[3].ToString()) + int.Parse(serial[4].ToString()) + int.Parse(serial[5].ToString()) + int.Parse(serial[6].ToString()) + int.Parse(serial[7].ToString());
sumA = sum.ToString().ToCharArray();


if (sum < 10) { serial[8] = '0'; serial[9] = sumA[0]; }
else { serial[8] = sumA[0]; serial[9] = sumA[1]; }






s10 = serial[0].ToString() + serial[1].ToString() + serial[2].ToString() + serial[3].ToString() + serial[4].ToString() + serial[5].ToString() + serial[6].ToString() + serial[7].ToString() + serial[8].ToString() + serial[9].ToString();






com1.CommandText = "insert into serialha_chap(cod8,cod2)values('" + s10 + "',12)";// شماره محصول عوض شود
com1.ExecuteNonQuery();






}
con1.Close();
MessageBox.Show("end proccess");
}
* */
}
}



لینک دانلود برنامه :
http://s5.picofile.com/file/8147553250/P1.rar.html (http://s5.picofile.com/file/8147553250/P1.rar.html)