Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Problem in Binding Data To an Array


Message #1 by psrr79@y... on Wed, 30 Oct 2002 20:57:57
Hi all, 
I am using a two tire web form. In the code behind page I am taking the 
value from one table(A1) and Inserting into the other table(A2). The 
problem is my Array value is binded to only the last value. All the values 
are not inserted from Table A1. 
Here is the Code: 
************************* 
public DataView GetData(){ 
SqlConnection sqlconn1=new SqlConnection(connstr1); 
sqlconn1.Open(); 
SqlCommand objCmd11 = new SqlCommand("Select Count(*) from A1 where 
DateDiff(yy,GetDate(),A1.DatePossed)=1", sqlconn1); 
int coun = Convert.ToInt32(objCmd11.ExecuteScalar());  
SqlCommand objCmd12 = new SqlCommand("Select Id,List from A1 where DateDiff
(yy,GetDate(),A1.DatePossed)=1 Order by Id", sqlconn1); 
objCmd12.CommandType = CommandType.Text; 
SqlDataReader objDR12 =objCmd12.ExecuteReader(); 
while(objDR12.Read()){ 
for(int i=0;i<coun;i++){ 
A1ID[i]=objDR12[0].ToString(); 
A1SL[i]=objDR12[1].ToString(); 
} 
} 
sqlconn1.Close(); 
sqlconn1.Open(); 
//sp_A2 is Stored procedure for inserting values from Table A1 

SqlCommand objComm = new SqlCommand("sp_A2", sqlconn1); 
objComm.CommandType = CommandType.StoredProcedure; 
objComm.Parameters.Add(new SqlParameter("@A1ID", SqlDbType.BigInt)); 
objComm.Parameters.Add(new SqlParameter("@A1SL", SqlDbType.NVarChar)); 
for(int y=0;y<coun;y++){ 
objComm.Parameters[0].Value =AID[y]; 
objComm.Parameters[1].Value =ASL[y]; 
} 
objComm.ExecuteNonQuery(); 
objComm.UpdatedRowSource = UpdateRowSource.None; 
sqlconn1.Close(); 
sqlstr="SELECT Id,List From A2"; 
SqlDataAdapter da1=new SqlDataAdapter(sqlstr,sqlconn1); 
DataSet ds1=new DataSet(); 
da1.Fill(ds1,"Trial"); 
return ds1.Tables["A2"].DefaultView; 
} 

I don't understand where I am going wrong. Only the last value from Table 
A1 is inserted into Trial. Table A1 has 4 values. Any help in this regard. 
Thanks, 
Psrr

  Return to Index