lỗi trong c# xin các pác Sửa Dùm

NguyenQuoc_tnt

Youtube Master Race
Tham gia ngày
6/7/10
Bài viết
14
Reaction score
0
mình muon insert từ file XML vào Database

string connetionString = null;
SqlConnection connection;
SqlCommand command;
SqlDataAdapter adpter = new SqlDataAdapter();
DataSet ds = new DataSet();
XmlReader xmlFile;
string sql = null;

int MaHSX = 0;
string TenHSX = null;

connetionString = "Data Source=NG_QUOC-PC;Initial Catalog=LinhKienMayTinh;Persist Security Info=True;User ID=sa;Password=123456789";

connection = new SqlConnection(connetionString);

xmlFile = XmlReader.Create("HangSanXuat.xml", new XmlReaderSettings());
ds.ReadXml(xmlFile);
int i = 0;
connection.Open();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
MaHSX = Convert.ToInt32(ds.Tables[0].Rows.ItemArray[0]);

TenHSX = ds.Tables[0].Rows.ItemArray[1].ToString();
/// loi ngay dong tren TenHSX nay/////////// Index was outside the bounds of the array.
sql = "insert into HangSanXuat values(" + MaHSX + ",'" + TenHSX + "')";
command = new SqlCommand(sql, connection);
adpter.InsertCommand = command;
adpter.InsertCommand.ExecuteNonQuery();
}
connection.Close();
MessageBox.Show("Insert Thành Công ");
 
vứt cái file xml lên đây xem nào bạn
 
Back
Top