我该如何解决这个问题 [英] How Do I Fix this issue

查看:87
本文介绍了我该如何解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Folks,我的一些代码存在一些问题,我对所有这些都是新手,所以我希望有比我更多的知识可以帮助我解决我的问题:)



基本上我有一个从表中提取数据的列表视图,可以通过edit / update命令编辑数据。好吧,因为我的数据库必须更改,因为有些列必须移动到新表中,它已经破坏了我的项目,让我对如何修复它感到困惑。基本上有人帮我输入了一个新的命令如下......



Hello Folks, im having some issues with some of my code, Im a novice of sorts to all this so Im hoping someone with more knowledge than me can help me fix my problems :)

Basically I had a list view that was pulling data from table and that data could be edited via the edit/update command. Well since my database had to be changed in that some of the columns had to be moved into new tables it has broken my project and has left me confused as to how to fix it. Basically someone has helped me input a new command as follows...

<asp:SqlDataSource ID="getmodule" runat="server" 

        ConnectionString="<%$ ConnectionStrings:UniString %>"

        SelectCommand="SELECT modules.id, modules.module_name, module_desc.pre_requisites, module_desc.co_requisites,
                        module_desc.compulsory_element, module_desc.course_contents, module_desc.supplementary_notes,
                        module_desc.learning_outcomes, module_desc.skills
                        FROM modules
                        INNER JOIN module_desc ON modules.id = module_desc.module_id
                        WHERE (modules.id=@module_id)"

        

        UpdateCommand="UPDATE [module_desc] SET [pre_requisites] = @pre_requisites, [co_requisites] = @co_requisites,
                        [compulsory_element] = @compulsory_element, [course_contents] = @course_contents, [supplementary_notes] = @supplementary_notes,
                        [learning_outcomes] = @learning_outcomes, [skills] = @skills
                        
                        WHERE [module_id] = @module_id">





现在第一个命令是有人在哪里工作,我的问题是我的问题更新命令,我试图从module_desc表中拉出colums并编辑它们,我也试图更新模块名称列,但是在另一个表中,我试图通过C#



第一个表的参数如下:





Now the first command was someone elses where it was working, my problem is with my update command, Im trying to pull the colums from the module_desc table and edit them, I also am trying to update a module name column but thats in a different table and Im trying to do that through C#

The parameters for the first table are as follows

<UpdateParameters>
            <asp:Parameter Name="pre_requisites" Type="String"/>
            <asp:Parameter Name="co_requisites" Type="String"/>
            <asp:Parameter Name="compulsory_element" Type="String"/>
            <asp:Parameter Name="course_contents" Type="String"/>
            <asp:Parameter Name="supplementary_notes" Type="String"/>
            <asp:Parameter Name="learning_outcomes" Type="String"/>
            <asp:Parameter Name="skills" Type="String"/>
            <asp:Parameter Name="module_id" Type="Int32" />
        </UpdateParameters>







我还有datakeyname和其他一些东西一起插入..

我的问题是,当我点击在浏览器中编辑页面本身并编辑说pre req字段并单击提交,不会出现任何错误,因此看起来它可以工作但它在数据库中更新并且页面只显示当前在数据库中的内容而不是更改.. 。



我在后端C#中使用以下代码来同时更新另一个表,因为我知道你不能用相同的更新命令更新2个表。 。




I also have datakeyname inserted along with some other stuff..
My problem is, when I click edit on the page itself in the browser and edit say pre req field and click submit, no error appears so it looks like it works but it dosent update in the db and the page just shows whats currently in the db and not the changes...

I was using the following code in the back end C# to update another table at the same time as I know you cant update 2 tables with same update command...

protected void displaymoduleinfo_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox ModuleName = displaymoduleinfo.EditItem.FindControl("module_nameTextBox") as TextBox;
        TextBox username = displaymoduleinfo.EditItem.FindControl("user_idTextBox") as TextBox;

        String modulename = ModuleName.Text;
        String user = username.Text;

        String connectionString = WebConfigurationManager.ConnectionStrings["UniString"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(connectionString);

        myConnection.Open();

        String query = "Update modules SET module_name = @module_name WHERE id= @user_id";

        SqlCommand cmd = new SqlCommand(query, myConnection);

        cmd.Parameters.AddWithValue("@module_name", modulename);
        cmd.Parameters.AddWithValue("@user_id", user);


        cmd.ExecuteNonQuery();


        myConnection.Close();







那里可能是太多的代码在这里让人们通过我了解我是新的,并不知道该网站如何显示代码或如果你可以把那么多,但基本上我只是想看看代码是否正确和或一个原因至于为什么它不起作用...



任何帮助都会非常感激......



Ryan




There might be too much code here for people to look thru I understand Im new and dont know much about how the site likes code displayed or if you can put that much up but basically im just looking to see if that code is right and or a reason as to why it aint working ...

Any help would be greatly apprecieted..

Ryan

推荐答案

ConnectionStrings:UniString %>

选择命令 = SELECT modules.id,modules.module_name,module_desc.pre_requisites,module_desc.co_requisites,
module_desc.compulsory_element,module_desc.course_contents,module_desc.supplementary_notes,
module_desc.learning_outcomes,module_desc.skills
FROM modules
INNER JOIN module_desc ON modules.id = module_desc.module_id
WHERE(modules.id=@module_id)




UpdateCommand = UPDATE [module_desc] SET [pre_requisites] = @pre_requisites,[co_requisites] = @co_requisites,
[compulsory_element] = @compulsory_element,[ course_contents] = @course_contents,[supplement_notes] = @supplementary_notes,
[learning_outcomes] = @learning_outcomes,[技能] = @skills

WHERE [module_id] = @module_id
>
ConnectionStrings:UniString %>" SelectCommand="SELECT modules.id, modules.module_name, module_desc.pre_requisites, module_desc.co_requisites, module_desc.compulsory_element, module_desc.course_contents, module_desc.supplementary_notes, module_desc.learning_outcomes, module_desc.skills FROM modules INNER JOIN module_desc ON modules.id = module_desc.module_id WHERE (modules.id=@module_id)" UpdateCommand="UPDATE [module_desc] SET [pre_requisites] = @pre_requisites, [co_requisites] = @co_requisites, [compulsory_element] = @compulsory_element, [course_contents] = @course_contents, [supplementary_notes] = @supplementary_notes, [learning_outcomes] = @learning_outcomes, [skills] = @skills WHERE [module_id] = @module_id">





现在第一个命令是别人的地方我正在工作,我的问题是我的更新命令,我试图从module_desc表中拉出colums并编辑它们,我也试图更新模块名称列,但那是在另一个表中,我试图通过C#



第一个表的参数如下





Now the first command was someone elses where it was working, my problem is with my update command, Im trying to pull the colums from the module_desc table and edit them, I also am trying to update a module name column but thats in a different table and Im trying to do that through C#

The parameters for the first table are as follows

<UpdateParameters>
            <asp:Parameter Name="pre_requisites" Type="String"/>
            <asp:Parameter Name="co_requisites" Type="String"/>
            <asp:Parameter Name="compulsory_element" Type="String"/>
            <asp:Parameter Name="course_contents" Type="String"/>
            <asp:Parameter Name="supplementary_notes" Type="String"/>
            <asp:Parameter Name="learning_outcomes" Type="String"/>
            <asp:Parameter Name="skills" Type="String"/>
            <asp:Parameter Name="module_id" Type="Int32" />
        </UpdateParameters>







我还插入了datakeyname以及其他一些东西..

我的问题是,当我在浏览器中点击页面本身上的编辑并编辑说pre req字段并单击提交时,不会出现任何错误,因此看起来它有效,但它在数据库中更新并且页面只显示当前位于Ť他db而不是更改...



我在后端C#中使用以下代码来同时更新另一个表,因为我知道你无法更新2个表具有相同的更新命令...




I also have datakeyname inserted along with some other stuff..
My problem is, when I click edit on the page itself in the browser and edit say pre req field and click submit, no error appears so it looks like it works but it dosent update in the db and the page just shows whats currently in the db and not the changes...

I was using the following code in the back end C# to update another table at the same time as I know you cant update 2 tables with same update command...

protected void displaymoduleinfo_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox ModuleName = displaymoduleinfo.EditItem.FindControl("module_nameTextBox") as TextBox;
        TextBox username = displaymoduleinfo.EditItem.FindControl("user_idTextBox") as TextBox;

        String modulename = ModuleName.Text;
        String user = username.Text;

        String connectionString = WebConfigurationManager.ConnectionStrings["UniString"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(connectionString);

        myConnection.Open();

        String query = "Update modules SET module_name = @module_name WHERE id= @user_id";

        SqlCommand cmd = new SqlCommand(query, myConnection);

        cmd.Parameters.AddWithValue("@module_name", modulename);
        cmd.Parameters.AddWithValue("@user_id", user);


        cmd.ExecuteNonQuery();


        myConnection.Close();







那里可能是太多的代码在这里让人们通过我了解我是新的,并不知道该网站如何显示代码或如果你可以把那么多,但基本上我只是想看看代码是否正确和或一个原因至于为什么它不起作用...



任何帮助都会非常感激......



Ryan




There might be too much code here for people to look thru I understand Im new and dont know much about how the site likes code displayed or if you can put that much up but basically im just looking to see if that code is right and or a reason as to why it aint working ...

Any help would be greatly apprecieted..

Ryan


尝试更改此内容:

Try changing this:
String query = "Update modules SET module_name = @module_name WHERE id= @class_name";
SqlCommand cmd = new SqlCommand(query, myConnection);
cmd.Parameters.AddWithValue("@module_name", modulename);
cmd.ExecuteNonQuery();



对此:


To this:

String query = "Update modules SET module_name = @module_name WHERE id= @class_name";
SqlCommand cmd = new SqlCommand(query, myConnection);
cmd.Parameters.AddWithValue("@module_name", modulename);
cmd.Parameters.AddWithValue("@class_name", "My Class Name, whereever it comes from");
cmd.ExecuteNonQuery();


这篇关于我该如何解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆