我有一个数据网格,我用一个数据集填充,有几个是这样完成的,它们可以工作,只有一个没有,为什么?
代码
<asp:DataGrid ID="dgServer" runat="server"
AutoGenerateColumns="False" AllowSorting="True"
ondeletecommand="dataGrid1_DeleteCommand"
oneditcommand="dataGrid1_EditCommand"
OnSortCommand="dataGrid1_SortCommand">
<AlternatingItemStyle BackColor="#C1D0EC" />
<Columns>
<asp:EditCommandColumn CancelText="Cancel" EditText="Editar"
UpdateText="Update">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:EditCommandColumn>
<asp:ButtonColumn CommandName="Delete" Text="Borrar"></asp:ButtonColumn>
<asp:BoundColumn DataField="Id" HeaderText="Id" SortExpression="Id"
Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="Server" HeaderText="Servidor"
SortExpression="Server" >
</asp:BoundColumn>
<asp:BoundColumn DataField="Port" HeaderText="Puerto" SortExpression="Port"
></asp:BoundColumn >
<asp:BoundColumn DataField="User" HeaderText="Usuario" SortExpression="User"
></asp:BoundColumn >
<asp:BoundColumn DataField="Password" HeaderText="Password" SortExpression="Password"
></asp:BoundColumn >
<asp:BoundColumn DataField="PassAuten" HeaderText="PassAut" SortExpression="PassAut">
</asp:BoundColumn>
</Columns>
<EditItemStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="#0B63A2" ForeColor="White" />
</asp:DataGrid>
如何在其他地方完成并且它有效:
public void LlenarDataGridServer()
{
//read = Con.executar_re("Select * from SMTP");
//dataGrid1.DataSource = read.Tables[0];
//dataGrid1.DataBind();
DataSet verServer = Con.executar_re("select * from dbo.smtp");
dgServer.DataSource = verServer.Tables[0];
dgServer.DataBind();
}
怎么回事,这简直要了我的命。谢谢。
编辑:是的,表已设置,我可以从 sql server 访问数据,并且是我计划更新的 1 行。
2 编辑:相同的行正在填充其他 DG,例如
public void LlenarDatagridConsecutivos()
{
read = Con.executar_re("select * from TypeCConsecutiveDocument");
dgConsecutivos.DataSource = read.Tables[0];
dgConsecutivos.DataBind();
}
和Con.etc:
public DataSet executar_re(string comando)
{
try
{
connnection01.Open();
SqlCommand command01 = new SqlCommand();
command01.CommandText = comando;
command01.Connection = connnection01;
SqlDataReader re01 = command01.ExecuteReader(CommandBehavior.CloseConnection);
DataSet ds = Convert(re01);
re01.Close();
connnection01.Close();
return ds;
}
catch (SqlException sqle)
{
System.Diagnostics.Debug.WriteLine(sqle.ToString());
DataSet ds = new DataSet();
return ds;
}