我有2個表Conturi
和Persoana
,我想要顯示每個單一的項目,我有(我不能使用ListView
),這樣做時遇到一個小問題。C#格式異常
表看起來是這樣的:
[Cont]:
- id (cheie primara)
- id_persoana (cheie externa in [Persoana])
- Banca (sir de caractere maxim 64)
- Sold (decimal)
- Unitate (moneda, sir de caracatere de lungime 3)
- Data_deschiderii (data)
我有麻煩搞清楚我的格式異常,這是代碼:
namespace TarnaLucianFlorinGrupa333
{
public partial class Conturi : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string query = GetQuery();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader reader = cmd.ExecuteReader();
FillTable(reader);
conn.Close();
}
private string GetQuery()
{
string query = string.Empty;
if (string.IsNullOrEmpty(TextBox1.Text))
{
query = string.Format("select c.id,p.Nume, c.Banca,c.Sold,c.Unitate,c.Data_Deschiderii from Cont c,Persoana p where c.Sold>={0} and p.Id = c.id_persoana", Convert.ToInt32(TextBox1.Text));
}
else
{
query = "select c.id,p.Nume, c.Banca,c.Sold,c.Unitate,c.Data_Deschiderii from Cont c,Persoana p where p.Id = c.id_persoana";
}
return query;
}
private void FillTable(SqlDataReader reader)
{
TableRow th = Table1.Rows[0];
Table1.Rows.Clear();
Table1.Rows.Add(th);
while (reader.Read())
{
TableRow row = new TableRow();
TableCell nume = new TableCell();
nume.Text = reader.GetValue(1).ToString();
row.Cells.Add(nume);
TableCell Banca = new TableCell();
Banca.Text = reader.GetValue(2).ToString();
row.Cells.Add(Banca);
TableCell Sold = new TableCell();
Sold.Text = reader.GetValue(3).ToString();
row.Cells.Add(Sold);
TableCell Unitate = new TableCell();
Unitate.Text = reader.GetValue(4).ToString();
row.Cells.Add(Unitate);
TableCell Data_Deschiderii = new TableCell();
Data_Deschiderii.Text = reader.GetValue(5).ToString();
row.Cells.Add(Data_Deschiderii);
TableCell Adauga = new TableCell();
Adauga.Text = string.Format("<a href=\"Adauga.aspx?id={0}\"> Adauga </a>", reader.GetValue(0).ToString());
row.Cells.Add(Adauga);
Table1.Rows.Add(row);
}
}
protected void Button2_Click(object sender, EventArgs e) { }
}
}
而且本所認爲:
<table>
<tr>
<td> Soldul </td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Cauta" />
</td>
</tr>
<tr>
<td colspan="3">
<asp:Table ID="Table1" runat="server">
<asp:TableHeaderRow BackColor=Aqua>
<asp:TableHeaderCell> nume </asp:TableHeaderCell>
<asp:TableHeaderCell> Banca </asp:TableHeaderCell>
<asp:TableHeaderCell> Sold </asp:TableHeaderCell>
<asp:TableHeaderCell> Unitate </asp:TableHeaderCell>
<asp:TableHeaderCell> Data_Deschidere</asp:TableHeaderCell>
<asp:TableHeaderCell> Adauga</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</td>
</tr>
</table>
它給我的錯誤是:
型「System.FormatException」的異常出現在mscorlib.dll,但在用戶代碼中沒有處理
Additional information: Input string was not in a correct format.
有人能指出我在哪裏,這是錯誤的?
在哪條線路到底如何?在Convert.ToInt32(TextBox1.Text)'? –
這是它告訴我的一切,我知道我......然後我可能會修復它... :(在排除故障時有一個與Datetime的鏈接,但我不明白爲什麼會這樣 –
這肯定不是它告訴你的全部內容 –