仅显示数据库中的值 [英] Only value in the database is displayed
问题描述
任务是我需要在文本框中添加值,当我点击additem按钮时,该值将被添加到radlistbox并在另一个页面中显示添加的值。当我添加值然后单击保存按钮时,仅显示我作为输入提供的最后一个值,并且未显示其他值。任何人都可以帮我解决这个问题。
The task is that I need to add values in the textbox and as I click on the additem button the value will be added to the radlistbox and to display the added values in the another page. As I add values and then click on the save button only the last value that I given as Input is been displayed and other values are not been displayed. Can anyone help me to sole this problem.
NewsTicker.NewsItemsCsv = repository.Rows[0]["NewsTickerItems"].ToString();
string[] split = this.uxNewTicker.Text.Split(',');
foreach (var s in split)
{
ShowRepositoryFields();
uxTickerItems.Items.Add(new RadListBoxItem(s));
}
上面的代码是在另一页显示值。
The above code is to display the values in another page.
<asp:Label ID="Label1" runat="server" AssociatedControlID="uxNewTicker">Enable Ticker</asp:Label>
<asp:CheckBox runat="server" id="tickerCheck"/><br />
<div id="tickerdisplay">
<asp:Label ID="Label2" runat="server" >News Items</asp:Label>
<asp:TextBox runat="server" ID="uxNewTicker" placeholder="Enter news item text" maxlength="150"></asp:TextBox>
<input type="submit" name="addItem" value="Add New Item" /><br />
<telerik:RadListBox runat="server" ID="uxTickerItems" Width="500px" Height="200px"
AllowReorder="true" AllowDelete="true" ShowCheckAll="True" PersistClientChanges="true" />
上面的代码是aspx代码显示。
The above code is the aspx code to display.
internal bool Save(ePIMS.Collaboration.Documents.Bll.Repository RepositoryObject, int DocumentRepositoryID, int ApplicationID, string RepositoryName, string Title, string BodyText,string NewsTickerItems, string Identifier )
{
return base.Save(RepositoryObject, "Save", "usp_DocumentRepositorySave",
new SqlParameter("@DocumentRepositoryID", DocumentRepositoryID),
new SqlParameter("@ApplicationID", ApplicationID),
new SqlParameter("@RepositoryName", RepositoryName),
new SqlParameter("@Title", Title),
new SqlParameter("@BodyText", BodyText),
new SqlParameter("@NewsTickerItems", NewsTickerItems),
new SqlParameter("@Identifier", Identifier)
);
}
上面的代码是将数据添加到数据库的SQL查询。
The above code is the SQL queries to add data to the database.
推荐答案
例如:
OdbcConnection connection = new OdbcConnection(MyConnectionString);
OdbcCommand queryCmd;
for example:
OdbcConnection connection = new OdbcConnection(MyConnectionString);
OdbcCommand queryCmd;
queryCmd = connection.CreateCommand();
queryCmd.CommandText = "Insert Into cli_detail(cli_Name,cli_Addr,cli_City,cli_State,cli_Country,Phonenumber,Comments,Gender,Dob,Age,Hobbies)values(?,?,?,?,?,?,?,?,?,?,?)";
queryCmd.Parameters.AddWithValue("@Cli_Name", txtName.Text);
queryCmd.Parameters.AddWithValue("@Cli_Addr", txtAddress.Text);
queryCmd.Parameters.AddWithValue("@Cli_City", txtCity.Text);
queryCmd.Parameters.AddWithValue("@Cli_State", txtState.Text);
queryCmd.Parameters.AddWithValue("@Cli_Country", txtCountry.Text);
queryCmd.Parameters.AddWithValue("@Phonenumber",Int32.Parse(txtPhonenumber.Text));
queryCmd.Parameters.AddWithValue("@Comments", txtComments.Text);
if (rdoFemale.Checked)
{
queryCmd.Parameters.AddWithValue("@Gender :" , rdoFemale.Text);
}
else
{
queryCmd.Parameters.AddWithValue("@Gender :" ,rdoMale.Text);
}
DateTime theDate = Convert.ToDateTime(dtpDob.Text) ;
queryCmd.Parameters.AddWithValue("@Dob" ,theDate.ToString("yyyy-MM-dd"));
queryCmd.Parameters.AddWithValue("@Age" ,Int32.Parse(nuAge.Text));
string hobies = "";
foreach (string chk in lstHobbies.SelectedItems )
{
hobies += "," + chk;
}
queryCmd.Parameters.AddWithValue("@Hobbies:", hobies);
var x= queryCmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
LoadData();
}
}
}
private void LoadData()
{
OdbcConnection connection=new OdbcConnection(MyConnectionString);
connection.Open();
try
{
OdbcCommand queryCmd = connection.CreateCommand();
queryCmd.CommandText="select * from table name";
OdbcDataAdapter adap = new OdbcDataAdapter(queryCmd);
DataSet ds = new DataSet();
adap.Fill(ds);
// DataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch(Exception)
{
throw;
}
finally
{
if(connection.State==ConnectionState.Open)
{
connection.Close();
}
}
}
这篇关于仅显示数据库中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!